OnlyFreeSearch library
☰
Game illustration for Trackside Light Switch.
Lighting

Trackside Light Switch

Give a night-driving course a trackside lamp that players can turn on and off.

Get Script ↗Test link · opens Google

About Trackside Light Switch

Use this Luau script inside your own Roblox Studio place. Its source is included below.

What it does

  • Shared lamp switch

    The first interaction switches on a PointLight. The prompt then reads “Turn off” so the next driver can reverse the change.

  • Light placement

    Stand at the entrance to a bend and compare the road with the lamp on and off. Increase Range if the lamp lights the verge but the turn itself is still dark.

How to run it

  1. Prepare the scene

    Create an anchored Part beside the track in your Studio place.

  2. Add the server Script

    Insert a server Script under that Part. Expand View Luau source and paste the code into the Script.

  3. Playtest the interaction

    Press Play, approach the Part, and activate the prompt. The first interaction switches on a PointLight. The prompt then reads “Turn off” so the next driver can reverse the change.

View Luau source
local part = script.Parent
local prompt = Instance.new("ProximityPrompt")
prompt.ActionText = "Turn on"
prompt.Parent = part
local light = Instance.new("PointLight")
light.Range = 18
light.Brightness = 2
light.Enabled = false
light.Parent = part
prompt.Triggered:Connect(function()
    light.Enabled = not light.Enabled
    prompt.ActionText = light.Enabled and "Turn off" or "Turn on"
end)

Questions

Can another player see the change?

Yes. The Script changes an object in Workspace on the server, so the effect is shared.

How should I position the Part?

Stand at the entrance to a bend and compare the road with the lamp on and off. Increase Range if the lamp lights the verge but the turn itself is still dark.

More scripts

View all ↗