Menu
CoddyTech

Doors That Swing

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

The lobby's door has a ProximityPrompt: near it, the player sees "E Open" (a tap on a phone), and pressing it fires the prompt's Triggered with the player.

A door turns on its hinge, not its middle. The door model has an invisible Hinge part at its edge. Where the panel is, measured from the hinge, is hinge.CFrame:ToObjectSpace(panel.CFrame); turn the hinge a quarter turn and put that back on, and you have the open door:

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

A tween makes it swing instead of jump. Once open, the door's Open attribute is set and its prompt switched off.

challenge icon

Challenge

Easy
  1. Get TweenService. Write openDoor(door): set the door's Open attribute, switch off door.Panel.Prompt, and tween the panel to the hinge's quarter turn (0.6 seconds).
  2. Write setupDoor(door): when the panel's prompt is triggered, open the door unless it is already open.
  3. Set up workspace.Rooms.Lobby.Door.

Press Play, walk to the door and press E. Then Check.

Try it yourself

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local Lighting = game:GetService("Lighting")
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")

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