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?
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.