Light switch remote event not working

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)

If they are both local scripts then using OnServerEvent won’t work because it only works on server scripts

So just scripts not local or module.

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)

You said in the post they where both local??

Are you trying to fire a remove event here?

image

IF so like what @Ooftius said it is :FireServer()

Yeah, I’ve tried with event:FireServer() but still no.

Is it a local script ur fireing the event from?

Yes it’s a local script, should it be normal script?

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)

It should work now :slight_smile:

Still doesn’t work, not sure why, no errors.

Did you put the local script into startercharacter scripts?

No, I’ll try in a sec. I’m gonna try a slight edit a sec.

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.

Here https://gyazo.com/809b587ffdd84fbb70043fab9d71fb8e, and here https://gyazo.com/ac1fa9c1a4267f661d4522bc07f05be5

Now it works, thanks for the help to everyone

its because a local script doesnt run in the workspace

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?

you can use the MessagingService | Roblox Creator Documentation

Okay, thanks will take a look at it later.