Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer
part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		-- its a part from a character
	else
		-- its a normal part
	end
end)

1 comment

0

this worked. thank you! :)

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.