I’m trying to make a button that will turn every light on the map on by triggering a remote event. Not sure why but the scripts don’t seem to be running, they’re both local scripts and the event is in the correct place.
--Button script
local part = script.Parent
local ClickDetector = part.ClickDetector
local event = game:GetService("ReplicatedStorage").Lights
local access = {"390251072", "415121515"}
script.Parent.MouseClick:Connect(function(player)
for _, access in pairs(access) do
if player.id == access then
event:LightsOn()
end
end
end)
--Light script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local event = game:GetService("ReplicatedStorage").Lights
local light = script.Parent.SpotLight
local function ChangeColour()
while true do
light.Color = Color3.fromRGB(255, 0, 0)
wait(5)
light.Color = Color3.fromRGB(0, 255, 0)
wait(5)
light.Color = Color3.fromRGB(255, 255, 255)
end
end
local function LightsOn()
light.Enabled = true
ChangeColour()
end
event.OnServerEvent:Connect(LightsOn)
Probably because you used LightsOn() instead of FireServer().
Try this.
--Button script
local part = script.Parent
local ClickDetector = part.ClickDetector
local event = game:GetService("ReplicatedStorage").Lights
local access = {"390251072", "415121515"}
script.Parent.MouseClick:Connect(function(player)
for _, access in pairs(access) do
if player.id == access then
event:FireServer()
end
end
end)
If you put the local script into startercharacterscripts and change the light effects to server script and put these codes into it works.
Local Script -
--Button script
local part = game.Workspace.Part -- Part That has light in it.
local ClickDetector = part.ClickDetector
local event = game:GetService("ReplicatedStorage").Lights
local access = {390251072, 415121515}
part.ClickDetector.MouseClick:Connect(function(player)
for _, access in pairs(access) do
if player.UserId == access then
event:FireServer()
end
end
end)
Server Script -
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local event = game:GetService("ReplicatedStorage").Lights
local light = script.Parent.SpotLight
local function ChangeColour()
while true do
light.Color = Color3.fromRGB(255, 0, 0)
wait(5)
light.Color = Color3.fromRGB(0, 255, 0)
wait(5)
light.Color = Color3.fromRGB(255, 255, 255)
end
end
local function LightsOn()
light.Enabled = true
ChangeColour()
end
event.OnServerEvent:Connect(LightsOn)
Could you screenshot the explorer? You don’t have to show everything just show where the lights script is located and the lights themselves, also show where the remote event is alongside the button script.
Just as a side question, does anyone know how to make it so you only click the button once and for every server the light will be on? Shall I just make it set a bool value?