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!
part.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then -- its a part from a character else -- its a normal part end end)
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.