Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i get the player with OnClientEvent (Remote Event)?

Asked by 5 years ago

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?

1 answer

Log in to vote
0
Answered by
Pojoto 329 Moderation Voter
5 years ago
Edited 5 years ago

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.

0
Oh, thanks! ieatandisbaconhair 77 — 5y
0
No problem! :) Pojoto 329 — 5y
Ad

Answer this question