Passing player argument through FireAllClients

  1. What do you want to achieve? Keep it simple and clear!

I’m trying to find the player that initiated the :FireAllClients event in a server script and then rename the “Text” value in a Textlabel to the name of that player.

  1. What is the issue? Include screenshots / videos if possible!

The issue is that I cannot correctly pass the player argument through the FireAllClients.

I’ll provide a video explanation in case it’s hard to understand.

HELP.wmv (3.3 MB)

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I’ve tried changing the Label Name with a Local script.

This fires the FireAllClients event when the start button is clicked.

script.Parent.MouseButton1Click:Connect(function()

	wait(1)
	game.ReplicatedStorage.Training:FireAllClients()
end)

This recieves the event and enables the join button on all clients.

local event = game.ReplicatedStorage.Training
local plr = game.Players.LocalPlayer

event.OnClientEvent:Connect(function()
	wait(2)

	script.Parent.Visible = true
	
end)


How are you “initiating” the FireAllClients?

Why not in your OnServerEvent connection, just pass the player who fired it (which is the first argument of OnServerEvent).

If you still don’t understand. Please provide the code and I can try to explain the process.

Some example code, following up on what @Ze_tsu said:

local serverRemote = game.ReplicatedStorage.RemoteEvent

serverRemote.OnServerEvent:Connect(function(player, ...)
--//The player who called the remote event is always the first argument for this event

serverRemote:FireAllClients(player) --//Pass that argument when we fire the remote for all clients
end)
1 Like

I will provide code but I want to explain it more first.
So by clicking the Start TextButton it initiates the FireAllClients and the FireAllClient event makes the Join button visible on all clients.

Once the TextButton is clicked you are of course firing the server as you cannot use :FireAllClients on the client. So in the server script where ever the OnServerEvent connection is located, you can just use the first argument that gets passed. Which is always the player who fired the remote!

Read @C_Sharper reply as he gave a good example of what you should do. Once you pass the player as an argument. You can just change your text label text to player.Name.

I’ve read his reply though I still do not completely understand

So what you’re doing is firing the same remote event to the server then to all the clients right after?

Exactly. I start by setting up the OnServerEvent on the server obviously, then you’d call the :FireServer() method on the client, and then from there that event will fire it back to all clients.

Lets say I fire a remote from the client to the server

-- Local script on the client 
Remote:FireServer("Random msg or whatever i want")

Now in a script on the server. My OnServerEvent connection will listen for the client to fire the remote:

-- Server script listening for the event to be fired
Remote.OnServerEvent:Connect(function(Player, MyArgument)
      print(Player) -- this would print the player who fired the client and it will always be the first argument passed for OnServerEvent
      print(MyArgument) -- This will print my argument that I've sent from the client which is "Random msg or whatever i want"
end)

Now you can use that first argument passed with OnServerEvent, the player, and send that as an argument when you use :FireAllClients():

-- Server script listening for the event to be fired
Remote.OnServerEvent:Connect(function(Player, MyArgument)
     Remote:FireAllClients(Player) -- Now we send the player as an argument!
end)

Now you would have the client listen for that event to be fired and simply change the text to the players name:

-- local script on the client
Remote.OnClientEvent:Connect(function(MyPlayerArgument)
     TextLabel.Text = MyPlayerArgument.Name -- MyPlayerArgument would be the player that we passed as an argument! 
end)

Note this is just an example and there may be typos!

1 Like

Ah, I get it now, I’ll give it a try

Thanks both of you for the help