Menu
CoddyTech

Room Templates

Lesson 4 of 20 in Coddy's Roblox Game: Escape the Dark course.

Behind the lobby door there is nothing yet. The rooms are templates in ServerStorage.Rooms, each a Model with an invisible Entrance part (its PrimaryPart, so it is the model's pivot) and an Exit part where its door is.

Placing a room after another is one line: put the new room's pivot, its entrance, on the old room's exit:

local room = ServerStorage.Rooms.Hall:Clone()
room:PivotTo(lastRoom.Exit.CFrame)

Which template comes next is in Settings.Order, a list of names. A new room's door needs setupDoor too.

challenge icon

Challenge

Medium
  1. Add local rooms = workspace.Rooms, local lastRoom = rooms.Lobby and local count = 0.
  2. Write addRoom() below setupDoor: add 1 to count, clone the template named Settings.Order[count], pivot it onto lastRoom.Exit, parent it to rooms, make it lastRoom, set up its door, and return it.
  3. Call addRoom() once at the end of the script.

Press Play and open the lobby door. 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)

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

-- 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
		openDoor(door)
	end)
end
setupDoor(workspace.Rooms.Lobby.Door)

-- 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)
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Roblox Game: Escape the Dark