Rising Lava
Lesson 10 of 18 in Coddy's Roblox Game: Endless Tower course.
Waiting at the bottom should not be safe. A sheet of lava starts under the tower and, after a short delay, rises steadily until it is 2 studs under the top, so everyone has to keep climbing.
A tween can wait before it starts: the sixth argument of TweenInfo.new is a delay in seconds. For a steady climb, the tween's time is the distance over the speed:
local seconds = top / Settings.LavaSpeed
local info = TweenInfo.new(seconds, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, Settings.LavaDelay)The lava is not solid (CanCollide false) so nobody can stand on it, and its Touched uses killOnTouch, the same function as the kill bricks. It starts at a height of -2 and rises to top - 2, exactly top studs.
Challenge
Medium- Near the top:
local lava = nil. MakebuildTowerreturntop. - Write
startLava(top): make an anchored Part namedLava, not CanCollide, 30 by 2 by 30, atVector3.new(0, -2, 0), orange Neon (Color3.fromRGB(255, 90, 20)), in the workspace, with Touched connected tokillOnTouch. Tween its Position toVector3.new(0, top - 2, 0)overtop / Settings.LavaSpeedseconds, Linear, after a delay ofSettings.LavaDelay. - At the end:
local top = buildTower()thenstartLava(top).
This lesson's lava is fast so the Check is quick. Press Play, then Check.
Try it yourself
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local CollectionService = game:GetService("CollectionService")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local Settings = require(game.ReplicatedStorage.Settings)
local stages = ServerStorage.Stages
local tower = nil
print("Each tower has " .. Settings.StageCount .. " stages")
-- Every player gets Wins on the leaderboard
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local wins = Instance.new("IntValue")
wins.Name = "Wins"
wins.Parent = leaderstats
end)
-- Anything tagged Kill ends a life
local function killOnTouch(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
-- A vanishing step fades soon after someone lands on it, then comes back
local function makeVanish(part)
part.Touched:Connect(function(hit)
if part:GetAttribute("Gone") or not hit.Parent:FindFirstChild("Humanoid") then
return
end
part:SetAttribute("Gone", true)
task.wait(Settings.VanishDelay)
part.Transparency = 0.8
part.CanCollide = false
task.wait(Settings.VanishTime)
part.Transparency = 0
part.CanCollide = true
part:SetAttribute("Gone", nil)
end)
end
-- A laser slides to its Slide offset and back, forever
local function makeSlide(part)
local info = TweenInfo.new(Settings.SlideTime, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, -1, true)
local goal = { Position = part.Position + part:GetAttribute("Slide") }
TweenService:Create(part, info, goal):Play()
end
-- A bounce pad throws whoever lands on it up into the air
local function bounce(hit)
local root = hit.Parent:FindFirstChild("HumanoidRootPart")
if root then
root.AssemblyLinearVelocity = Vector3.new(0, Settings.BouncePower, 0)
end
end
-- Spinners turn a little every frame
RunService.Heartbeat:Connect(function(dt)
for _, spinner in CollectionService:GetTagged("Spinner") do
if spinner:IsDescendantOf(workspace) then
spinner:PivotTo(spinner:GetPivot() * CFrame.Angles(0, math.rad(Settings.SpinSpeed) * dt, 0))
end
end
end)
-- Turn on every obstacle in a stage, by its tags
local function setupStage(stage)
for _, part in stage:GetDescendants() do
if part:HasTag("Kill") then
part.Touched:Connect(killOnTouch)
end
if part:HasTag("Vanish") then
makeVanish(part)
end
if part:HasTag("Conveyor") then
part.AssemblyLinearVelocity = part.CFrame.LookVector * Settings.BeltSpeed
end
if part:HasTag("Slider") then
makeSlide(part)
end
if part:HasTag("Bounce") then
part.Touched:Connect(bounce)
end
end
end
-- Any stage, at random
local function pickStage()
local all = stages:GetChildren()
return all[math.random(1, #all)]
end
-- Put a copy of a model on top of the tower; returns the copy and the new top
local function stack(template, bottom)
local copy = template:Clone()
local box, size = copy:GetBoundingBox()
local lift = bottom - (box.Position.Y - size.Y / 2)
copy:PivotTo(copy:GetPivot() + Vector3.new(0, lift, 0))
copy.Parent = tower
return copy, bottom + size.Y
end
-- Build a new random tower, bottom up
local function buildTower()
tower = Instance.new("Model")
tower.Name = "Tower"
tower.Parent = workspace
local top = 0
for i = 1, Settings.StageCount do
local stage, newTop = stack(pickStage(), top)
top = newTop
setupStage(stage)
end
stack(ServerStorage.Finish, top)
end
buildTower()
This lesson includes a short quiz. Start the lesson to answer it and track your progress.