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)
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)
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
Thank that work!