Vanishing Steps
Lesson 6 of 18 in Coddy's Roblox Game: Endless Tower course.
Glass steps tagged Vanish fade away soon after you land on one, then come back. A part with CanCollide off is walked through, and with a high Transparency it looks gone:
part.Transparency = 0.8
part.CanCollide = falseTouched fires for every limb that touches, and again as you fall through the step. Without a check, each touch starts its own fade, and the step flickers long after you have gone. A debounce lets only the first one through: mark the step while it is busy, and ignore touches while the mark is there.
if part:GetAttribute("Gone") then
return
end
part:SetAttribute("Gone", true)
-- fade, wait, come back
part:SetAttribute("Gone", nil)The waiting happens inside the Touched function, which Roblox runs on its own, so it never holds up the rest of the game.
Challenge
MediumWrite makeVanish(part) and use it for every part tagged Vanish in setupStage. When something with a Humanoid touches the step and it is not already gone:
- Set the attribute
Goneto true. - Wait
Settings.VanishDelay, then set Transparency to 0.8 and CanCollide to false. - Wait
Settings.VanishTime, then set them back to 0 and true, and clearGone(set it to nil).
Press Play and keep moving. 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 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
-- 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
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.