SonerPamuk
(SonerPamuk)
February 22, 2021, 9:33pm
#1
Hello everyone Soner here.
So I tried making a GUI that allows you to control lights with a button (only 1 light and button currently)
Explaining the situation:
So I have a GUI that has a button In It, If you click on that button a light that Is In workspace will get disabled
I tried using remote events but It didnt work, I probably did It wrong but I don’t really know, can someone help me?
Vulkarin
(Vulkarin)
February 22, 2021, 9:34pm
#2
Can you show the attempt? Sounds like you were on the right path - assuming that you want the light turning on to replicate.
SonerPamuk
(SonerPamuk)
February 22, 2021, 9:38pm
#3
There Is a screen gui and It has a local script in it
game.ReplicatedStorage.OnOff.OnClientEvent:Connect(function()
game.Workspace.blabla.light.Enabled = false
end)
And the button has this script:
(local btw)
script.Parent.Frame.TextButton.MouseButton1Click:Connect(function()
game.ReplicatedStorage.OnOff:FireClient()
end)
I’m pretty bad at using remote events so I don’t know If I did something wrong.
the button and the local script are In the same GUI
The remote event Is In ReplicatedStorage
Vulkarin
(Vulkarin)
February 22, 2021, 9:44pm
#4
Okay so RemoteEvents are used when you want Client → Server communication or vice versa. You can think of LocalScripts as code which the client runs and Scripts as what runs on the server.
In this case, the client is doing an action (clicking a button in a GUI) and the server will respond by toggling a light. Thus, this code needs to go into a Script (ran by the server). Notice how I replaced OnClientEvent()
with OnServerEvent()
.
game.ReplicatedStorage.OnOff.OnServerEvent:Connect(function()
game.Workspace.blabla.light.Enabled = false
end)
And this code (which is the way you have it) needs to be run by the client (LocalScript). Notice how I replaced FireClient()
with FireServer()
.
script.Parent.Frame.TextButton.MouseButton1Click:Connect(function()
game.ReplicatedStorage.OnOff:FireServer()
end)
2 Likes
SonerPamuk
(SonerPamuk)
February 22, 2021, 9:45pm
#5
Oh thanks, I’ll try It and reply back to you asap