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

FireClient player argument must be a player object?

I'm trying to make a script that opens a player's Gui when they touch a block. When the player touches the block, it fires an event to the client. This works in studio, however it does not in "Play" mode. I get the error "FireClient player argument must be a player object" This is my script

function openGui(player) local user = game.Players:FindFirstChild(player.Parent.Name) open:FireClient(user.Character) end

function closeGui(player) local user = game.Players:FindFirstChild(player.Parent.Name) close:FireClient(user.Character) end

player.Parent (player = body part of the player that touched the block, Parent = the player's character) Nothing seems to fix this :/ I tried making the game search the players list for a player with the same name as player.Parent, but that doesn't fix it either.. Help?

1 answer

Yes.

When using a remote event (RE) or remote function (RF), the first argument is the player object when firing from the server.

For example (On the server):

RE:FireClient(Player, args)

"Player" tells the remote event which player should receive the call. "Args" can be any value. You can pass any amount of arguments through the remote event.

RE:FireAllClients(args)

When using "FireAllClients", the remote event fires to every client in-game, so no designation is needed. Treat args like above.

IMPORTANT: You can use "FireAllClients" or "FireClient" in ONLY server scripts (Scripts) OR module scripts called by server scripts.

When listening for the call on the client, you should use this:

RE.OnClientEvent:Connect(function(Args) -- Code end)

Notice how the "Player" argument isn't the first argument anymore? That is because Roblox removes it as you can get the player using "LocalPlayer", so the argument would be redundant.

IMPORTANT: You can only use "OnClientEvent" in ONLY Local Scripts or module scripts called by Local Scripts.

Note: It is good practice to put RemoteEvents and Functions in ReplicatedStorage as both the server and client can see that service.

4 comments

0

thanks for the Info, but I'm still struggling to fire the event to the player touching the block

0

Nevermind, I've figured it out. Thanks :D

0

Im seraching around the internet for the same roblem i had when i put Player in the thing its and unknown global help? :)

0

Nvm i got it

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