Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Question about the plr argument in FireClient?

Ok, so with FireClient, the first argument must be the player, right? Well, I'm having some issues. Ok, so lets say I run this in a server script

game.ReplicatedStorage.RemoteEvent:FireClient(plr,"one","two")

and in the localscript, the code would be

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(plr,1,2)
print(plr,1,2)
end)

the output would be (one two nil) and if I try to remove player it fails to cast value (or something like that) and I really need it to pass player, which it isnt doing.. ive tested it in the normal command bar, studio solo mode, and Clients and Servers mode they all return plr nil. any help?

PLEASE DO NOT SPOON FEED ME.

4 comments

0

Can't pass the player in OnClientEvent.

0

I thought it was required?

0

It's required in FireClient, not OnClientEvent.

0

so whats the point of passing player as an argument in FireClient but you cant use it in OnClientEvent??

1 answer

✓ Accepted answer

Alright I'll try to make this quick and easy to understand

game.ReplicatedStorage.RemoteEvent:FireClient(plr,"one","two")

The first Parameter is the player for when you want to fire an event to a single player, that single player is in your code defined by "plr".

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(plr,1,2)
	print(plr,1,2)
end)

The plr is not sent to the function here, it's just a parameter the FireClient event uses to define which player to send "one", and "two".

instead you would want to write this

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(1,2)
	print(game.Players.LocalPlayer,1,2)
end)

game.Players.LocalPlayer gets the player that is running the LocalScript

This discussion is preserved as it was. New answers, comments, and votes are closed.