I am trying to make a game where you need to press a button to unlock an exit. The button model I am using has a ClickDetector inside of it. I also have a Script, RemoteEvent, and LocalScript inside as well. I tried to program my Script to fire the RemoteEvent on the Client. Then, my LocalScript will receive that Client Fire and will make the button turn green, and unlock the Exit for ONLY the player who clicked the button. Not the whole server.
The thing is, when I run the game and click the button, it doesn't do anything and gives me this Output Error:
Argument 1 missing or nil - Server - Script:2
This is the code for the ClickDetector Script (The Normal Script):
script.Parent.ClickDetector.MouseClick:Connect(function(player) script.Parent.ButtonEvent:FireClient() end)
This is the code for the LocalScript (The Client Receiver Script):
script.Parent.ButtonEvent.OnClientEvent:Connect(function() script.Parent.BrickColor = BrickColor.new("Lime green") end)
I have also tried making the Normal Script turn the button Green, but it happens for the whole server (which I don't want).
Any help on this?
Hello,
You have made a mistake in the argument of the Server Script that you haven't defined which Player the server will trigger the event for. The FireClient()
should have the first Parameter of FireClient(Player)
(Player). This would be like,
Code Example, Triggering Remote Event to Client
script.Parent.ClickDetector.MouseClick:Connect(function(player) script.Parent.ButtonEvent:FireClient(player) <-- end)
Just found out that you can't use :FireClient() and have your event in the ReplicatedStorage. I didn't know that.