Menu
CoddyTech

Room Numbers

Lesson 6 of 25 in Coddy's Roblox Game: Escape the Dark course.

A player should know how deep they are. Every room gets its number: as an attribute, Number, and on the sign over its door (Sign.SurfaceGui.Number).

Each room has an invisible Entry part a step inside its entrance. When a player's body touches it, that room becomes their Room on the leaderboard and their checkpoint: a player's RespawnLocation is the SpawnLocation they come back at, and each room has one, Checkpoint.

player.RespawnLocation = room.Checkpoint

Players:GetPlayerFromCharacter(hit.Parent) says whose body touched it, or nil.

challenge icon

Challenge

Medium

Number the rooms and make them checkpoints.

  1. Give each player leaderstats with an IntValue Room.
  2. In addRoom, set the Number attribute to count and room.Sign.SurfaceGui.Number.Text to "Room " .. count.
  3. Write setupEntry(room), called for the Lobby and each new room: touching room.Entry sets the player's Room to its Number, RespawnLocation to room.Checkpoint.

Press Play and walk into room 1: its sign and your Room read 1. Then Check.

Try it yourself

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local Lighting = game:GetService("Lighting")
local TweenService = game:GetService("TweenService")
local Settings = require(game.ReplicatedStorage.Settings)

local rooms = workspace.Rooms
local lastRoom = rooms.Lobby -- the newest room
local count = 0 -- rooms made so far

-- Night falls: no sun, a little light everywhere, and fog
Lighting.ClockTime = Settings.ClockTime
Lighting.Ambient = Settings.Ambient
Lighting.OutdoorAmbient = Settings.Ambient
Lighting.FogColor = Color3.new(0, 0, 0)
Lighting.FogEnd = Settings.FogEnd
print("Lights out")

-- Swing a door open on its hinge
local function openDoor(door)
	door:SetAttribute("Open", true)
	door.Panel.Prompt.Enabled = false
	local hinge, panel = door.Hinge, door.Panel
	local goal = hinge.CFrame * CFrame.Angles(0, math.rad(90), 0) * hinge.CFrame:ToObjectSpace(panel.CFrame)
	TweenService:Create(panel, TweenInfo.new(0.6), { CFrame = goal }):Play()
end

local addRoom -- written below: a door adds a room, and a room has a door

-- What a door does when a player opens it
local function setupDoor(door)
	door.Panel.Prompt.Triggered:Connect(function(player)
		if door:GetAttribute("Open") then
			return
		end
		if door.Parent == lastRoom then
			addRoom()
		end
		openDoor(door)
	end)
end
setupDoor(workspace.Rooms.Lobby.Door)

-- Lesson 6: Room Numbers goes here

-- A new room at the exit of the newest one
function addRoom()
	count += 1
	local name = Settings.Order[(count - 1) % #Settings.Order + 1]
	if count >= Settings.RoomsToEscape then
		name = "Exit"
	end
	local room = ServerStorage.Rooms[name]:Clone()
	room:PivotTo(lastRoom.Exit.CFrame)
	room.Parent = rooms
	lastRoom = room
	setupDoor(room.Door)
	return room
end

-- Every player: a flashlight every life
Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		local flashlight = ServerStorage.Flashlight:Clone()
		flashlight.Parent = player.Backpack
		local beam = flashlight.Handle.Beam
		flashlight.Activated:Connect(function()
			beam.Enabled = not beam.Enabled
		end)
	end)
end)

All lessons in Roblox Game: Escape the Dark

Practice on your own: Roblox playground