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

How to know who touch the part?

Hello, I'm a beginner developer and I want know how to find the player touch the part..

function ontouch()
	print('player')
end

script.Parent.Touched:connect(ontouch)

1 answer

✓ Accepted answer

Hi olivieralain111! I'm here to help you!

To know who touch the part use the player service and :GetPlayerFromCharacter()

function ontouch(hit)
	local player = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
	if player then
		print(player.Name)
	end
end

script.Parent.Touched:Connect(ontouch) -- Use :Connect(), :connect() is deprecated

simple version:

script.Parent.Touched:Connect(function(hit)
	local player = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
	if player then
		print(player.Name)
	end
end)

1 comment

0

Thank that work!

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