Whydo we said if humanoid~=nil then

why do we said if humanoid~=nil then when we work with touch

1 Like

to check if the humanoid exists or not

1 Like

but if he touched the part he exist no?

other parts can touch it without a humanoid too

Why do you even create a post for a question like this? Just check what touched event and if statement is

1 Like

Or you can do if humanoid then
same thing basically

We do that to make sure what the part is touching is actually a character, with a Humanoid. If we don’t, it can result in errors and subsequently break the script.

Let’s say you load in a map. There is a permanent kill brick on the map that relies on the .Touched signal. When you load in the new map, the .Touched signal would fire for any loaded part that touches the kill brick. If we attempted to kill the map part, it would throw an error and break the script.

This is why humanoid checking is absolutely essential when dealing with .Touched signals.

Let me know if you have any more questions.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.