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