Hello everyone, I've been trying to fire a remoteevent, but things aren't going right
Here's what I put down
In a normal script in a GUI button:
local Players = game:GetService("Players") local player = Players.LocalPlayer local function mouseclick() game.ReplicatedStorage.RewardChange:FireClient(player) print("Fired") end script.Parent.MouseButton1Down:Connect(mouseclick)
And for the receiving end, there's a localscript in Workspace (I made it local as I'm trying to change the PlayerGui)
game.ReplicatedStorage.RewardChange.OnClientEvent:Connect(function() print("received")
I also put my RemoteEvent in Workspace so the localscript
As you can see, I tried troubleshooting it with a print troubleshoot, but that doesn't print.
Thanks, any help would be appreciated
The reason it doesn't work is because you can't fire the client from a client. You can, however, ues a BindableEvent
which is basically the same as a RemoteEvent but instead of server to client it's client to client or server to server.
replace "RewardChange" with a BindableEvent
local Players = game:GetService("Players") local player = Players.LocalPlayer local function mouseclick() game.ReplicatedStorage.RewardChange:Fire(player) print("Fired") end script.Parent.MouseButton1Down:Connect(mouseclick)
Script 2
game.ReplicatedStorage.RewardChange.Event:Connect(function() print("received")
Unless the GUI button is a sever script, in which case LocalPlayer isn't available.
Also, the LocalScript MUST be parented to StarterGui
, the Character, StarterPack
, or StarterPlayerScripts