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

How to get a player from a touched event, not a character?

Asked by 9 years ago

I am making a touched event on a door that makes a GUI appear. But I just realized I need to put it in the player, not the character, except that touched events give the character, not the player. Help?

1 answer

Log in to vote
5
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

The GetPlayerFromCharacter method of game.Players is what you're looking for:

part.Touched:connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        --code
    end
end)
2
Thanks for the fast answers! groovydino 2 — 9y
2
Please provide an explanation behind your answer so the User has a better understanding on how to use it properly. :) TheeDeathCaster 2368 — 9y
0
There's really not much to explain, Alpha. `GetPlayerFromCharacter` is not a cryptic function name, and groovy already knows how to get the Character from a Touched event, as evidenced by his original question. adark 5487 — 9y
2
I'm pretty sure the Function Name is self-explanatory. DigitalVeer 1473 — 9y
Ad

Answer this question