The issue is: when I fire the client, it doesn’t get triggered (I’ve used test prints, and everything printed out, except for when I got the to remote event trigger)
Example code (Server):
local Events = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents", 10)
local exampleEvent = Events:WaitForChild("EventName", 10)
exampleEvent:FireAllClients(randomParams)
Example code (Client):
local Events = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents", 10)
local exampleEvent = Events:WaitForChild("EventName", 10)
exampleEvent.OnClientEvent:Connect(function() print("Fired") end
Instead of it printing “Fired”; it prints nothing.
if this is exactly how the code is written, theres a chance the server is firing the event before the client is loaded up and ready to receive the event thats fired. Try adding a wait(5) or something to the server and see if that works
I am assuming that your example code is also what you are currently using, or is identical enough to how your real code is written.
The server will always fire RemoteEvents/Functions before a player gets to fully join. That means if the server is initiated, FireClient() and FireAllClients() will be called immediately. But, since the player still has to join, they won’t receive the event because they got in the game later than when the server called the aforementioned functions.
Therefore, try using Players.PlayerAdded:Wait() and task.wait(seconds) before you call FireAllClients().
For any else who had this problem I’ll give a detailed solution.
When you fire the client on the server immediately, the players haven’t been registered in the game yet, so if call for example “Event:FireAllClients()”, there will be no clients to fire since a player haven’t been registered in the server yet. A way to get around this, if you want to immediately fire the event when a player joins, is to just do:
local PlayerService = game:GetService('Players')
local Event = 'Example (Replace Your Event Here)' :: RemoteEvent
PlayerService.PlayerAdded:Connect(function(plr)
Event:FireClient(plr) -- Or you could do Event:FireAllClients()
end)
-- Or if you only want the event to be called once, do:
PlayerService.PlayerAdded:Once(function(plr)
Event:FireClient(plr) -- Or you could do Event:FireAllClients()
end)