Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why Does The Remote Event Fire For One Player?

Asked by 5 years ago

What is the problem?

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).

1 answer

Log in to vote
1
Answered by
LeadRDRK 437 Moderation Voter
5 years ago
Edited 5 years ago

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!

0
yup, thats what i was gonna put. Plieax 66 — 5y
0
I'll test it out saSlol2436 716 — 5y
0
Well, when the player joins, it is supposed to have the same thing. For example, if a player joined and it was counting down from 100 to 0. Let's say it is at 73, when another player joins. It should be 73, not from the beggining saSlol2436 716 — 5y
0
This is definately not my problem. You didn’t include the countdown script or anything. This script of yours is just for creating a gui I assume LeadRDRK 437 — 5y
View all comments (2 more)
0
But it looks like you have a lot of syncing problem, try storing the time on the server then fire it to the clients LeadRDRK 437 — 5y
Ad

Answer this question