Menu
CoddyTech

Vanishing Steps

Lesson 7 of 21 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 = false

Touched 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 icon

Challenge

Medium

Make the glass steps vanish under you.

  1. Write makeVanish(part): on Touched, if a character touched and the attribute Gone is not set, set it to true.
  2. Wait Settings.VanishDelay, set Transparency 0.8 and CanCollide false; wait Settings.VanishTime, undo both and set Gone to nil.
  3. In setupStage, call it for parts tagged Vanish.

Press Play and stop on a glass step: it fades, then comes back. 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

-- Lesson 7: Vanishing Steps goes here

-- 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()

All lessons in Roblox Game: Endless Tower

Practice on your own: Roblox playground