I made a script that shows a gui for a client when he steps on a pad. But since OnClientEvent doesnt have a player argument, i cant make it to show the gui. How do i get the player?
✓ ANSWER ACCEPTED
How do i get the player with OnClientEvent (Remote Event)?
1 answer
✓ Accepted answer
Whenever you want to FireClient(), you have to put a player argument in the parentheses. This tells the server which player to fire to.
For example, in your situation:
local object = script.Parent
local remoteEvent = --wherever your Remote Event is located
object.Touched:Connect(function(otherPart)
--check if object is a player--
remoteEvent:FireClient(otherPart.Parent)
end)
This would fire the remote event to the player who touched it, and then in a different script:
local remoteEvent = --wherever it's located--
remoteEvent.OnClientEvent:Connect(function()
--display gui--
end)
Basically, OnClientEvent doesn't have a player argument because the script it is running in is inside the player, but FireClient() does have a player argument so the server can know which player to send it to.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Oh, thanks!
No problem! :)