Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how do i check if a player is touching a part?

Asked by 5 years ago

would help me out quite a bit

1 answer

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago

Using part's Touched event:

The code below says when the parts touch event is fired, call the following function:

part = game.Workspace.Part

part.Touched:Connect(function(itemTouchingPart)
    print("Item touching part: ", itemTouchingPart)

    --Now we're going to see if the thing touching the part is a person by checking if it's parent is one of the players in game
    if(itemTouchingPart.Parent and game.Players:FindFirstChild(itemTouchingPart.Parent.Name))then
        print("There is a player touching the part!")
    end

end)
Ad

Answer this question