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

Check if a part touched is a Part and not a player?

Asked by 4 years ago

In my puzzle game, I am making a part which detects if another part touches it, which then opens a door.

It works well, but the door opens when anything touches it.

How can I make it tell what kind of thing it touched, i.e knowing that it touched a Part or a Humanoid, etc. etc.

Thanks for the help!

2 answers

Log in to vote
0
Answered by
Necro_las 412 Moderation Voter
4 years ago
part.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        -- its a part from a character
    else
        -- its a normal part
    end
end)
0
this worked. thank you! :) wolffdonnaven 12 — 4y
Ad
Log in to vote
1
Answered by
Raccoonyz 1092 Donator Moderation Voter
4 years ago
Edited 4 years ago
script.Parent.Touched:Connect(function(hit)
    if game.Players:FindFirstChild(hit.Parent.Name) == nil and game.Players:FindFirstChild(hit.Parent.Parent.Parent.Name) == nil then -- Making sure the part isn't a descendant of a player
    print("Is a part")
else
    print("Is a player")
end
end)

What this does is checks the "Players" for any player named the user's name. This won't work if the part is named a player in game, so I would suggest using special characters like "|" in the name to make sure it works.

Answer this question