BoolValue not changing

I need a GUI button to change a boolvalue but it is not working
I also need to know if it needs to be a script or local script

function OnClicked() 
	script.Parent.Parent.Parent.Parent.Body.Lights.On.Value = true

end 

script.Parent.MouseButton1Down:connect(OnClicked)

Is it a script or a localscript?

If it’s a local script, it will only change on the client, so the server will not see it. If you want it to be seen by the server, you will need to fire a remote event.

It is a Local script not a normal script

You have to detect the clicking client-sidedly then send a message through a remote event, receive that message from the server. Then change it server sidedly.

If you do not do this exactly it will not working, due to a few points:

  1. Changing a value client-sidedly will not update server-sided scripts, so it wont update other players.
  2. Detecting a mouse click on a GUI object can only be detected by a client-sided script.

Client-sided script:

local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("EventName")

function OnClicked() 
	RemoteEvent:FireServer(script.Parent.Parent.Parent.Parent.Body.Lights.On)
end 

script.Parent.MouseButton1Down:connect(OnClicked)

Server-sided script:

local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("EventName")
RemotEvent.OnServerEvent:Connect(function(player, valueToToggle)
    -- Toggle the light here.
    valueToToggle = true
end)

If you do not know how RemoteEvents work, I highly suggest to deepen yourself in this subject.

You can actually detect the clicking in a server script as well, at least you used too.

Server script in the button:


function OnClicked() 
	script.Parent.Parent.Parent.Parent.Body.Lights.On.Value = true
end 

script.Parent.MouseButton1Down:connect(OnClicked)