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

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

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

✓ Accepted answer

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)

4 comments

2

Thanks for the fast answers!

2

Please provide an explanation behind your answer so the User has a better understanding on how to use it properly. :)

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.

2

I'm pretty sure the Function Name is self-explanatory.

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