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

How do I get 'player' from a touch event?

I need to access the player gui to enable a message to be displayed on their screen when they touch a part but I'm unsure how to do it. Can anyone please help?

Normally, you can access the character without a problem but I don't know how to get the player.

2 answers

✓ Accepted answer

The GetPlayerFromCharacter function returns the Player associated with the given character.

So to get the player from a touched event you would do something like this:

local part = workspace.Part
part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then -- part belongs to character
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	end
end)

That's it, you got your player.

Hope I helped, if you have any questions please let me kno1!

1 comment

0

Thanks so much!

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