As the question says, I know how to do the onChatted, but how do I make something happen when a player runs into a part?
COMMUNITY QUESTION
How do you do something when someone touches something?
1 answer
Use the .Touched event.
The Touched event has one argument - the other part that touched it. To tell if the other part belongs to a player, you have to check if that part is inside a Model with a Humanoid object.
game.Workspace.Part.Touched:connect(function(otherPart)
--check if the other part belongs to a character
if (otherPart.Parent and otherPart.Parent:FindFirstChild("Humanoid")) then
local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
if player then
print("Touched by " .. player.Name)
end
end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.
