I have a server. There is one player. Then, then, another player joins. The problem is that when I use the remote event, it only fires for the player that was already there, but, for the other player that joined, it doesn't work.
Server
--\\ Services local repStorage = game:GetService("ReplicatedStorage") --\\ Network Data local remoteEvent = repStorage:WaitForChild("RemoteEvent") remoteEvent:FireAllClients()
Client
--\\ Services local repStorage = game:GetService("ReplicatedStorage") --\\ Network Data local remoteEvent = repStorage:WaitForChild("RemoteEvent") remoteEvent.OnClientEvent:Connect(function() local gui = Instance.new("ScreenGui") gui.Parent = script.Parent -- assuming the parent of this client script is PlayerGui local txt = Instance.new("TextLabel") txt.Text = "Remote Fired" txt.Parent = gui end)
You see, I am working with the Client(see the GUI's).
The problem here is your server; you made it fire all clients, but only once, so when the other player joins, the event doesn’t fire again and the player doesn’t receive the signal. To resolve this, use the PlayerAdded
event of the Players
, which fires everytime a player joins:
--\\ Services local repStorage = game:GetService("ReplicatedStorage") local Players = game:GetService("Players") --\\ Network Data local remoteEvent = repStorage:WaitForChild("RemoteEvent") Players.PlayerAdded:Connect(function(plr) remoteEvent:FireClient(plr, nil) end)
You also don’t need to use FireAllClients
, just fire once to the player who just joined.
If it works for you, please upvote and accept this answer!