why do we said if humanoid~=nil then when we work with touch
to check if the humanoid exists or not
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
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.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.