The Flashlight
Lesson 2 of 20 in Coddy's Roblox Game: Escape the Dark course.
In the dark you need a flashlight. It is a Tool in ServerStorage, and its Handle holds a SpotLight named Beam: a cone of light out of one face of the part, the front of the flashlight.
A player's Backpack is emptied every time they spawn, so the flashlight is handed out on each CharacterAdded. A click with a tool in hand fires its Activated event, on the server too, and that switches the beam:
flashlight.Activated:Connect(function()
beam.Enabled = not beam.Enabled
end)Press 1 to hold it, and click to switch it on.
Challenge
EasyWhen a player joins, on every CharacterAdded: clone ServerStorage.Flashlight into their Backpack, and connect its Activated to switch Handle.Beam.Enabled.
Press Play, press 1 and click. 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")
This lesson includes a short quiz. Start the lesson to answer it and track your progress.