Any suggestions as to how to prevent this error I've been getting from this script I made.
script.parent.houseSize.TouchEnded:connect(function(touch) if touch.Parent.Humanoid then print("idk") end end)
the error:
20:51:57.846 - Humanoid is not a valid member of Accessory 20:51:57.847 - Stack Begin 20:51:57.847 - Script 'Workspace.miscScripts.Script', Line 26 20:51:57.848 - Stack End
You're close :)
You have to check it with the FindFirstChild
function, otherwise you could be indexing a nil value.
script.parent.houseSize.TouchEnded:connect(function(touch) if touch.Parent:FindFirstChild("Humanoid") then --FindFirstChild function print("idk") end end)
Hi!
It seems like one of your hats is coming in contact with the houseSize, cuing the function. The problem with hats is that their parent is not the character, but instead its parent's parent.
Like this: Character > Accessory > Handle
Also, instead of using "Parent.Humanoid", you need to use "Parent:FindFirstChild("Humanoid")" if you're trying to determine if there is a humanoid within the model. Otherwise, if there is no humanoid it will cause a nil error.
script.parent.houseSize.TouchEnded:connect(function(touch) if touch.Parent:FindFirstChild("Humanoid") or touch.Parent.Parent:FindFirstChild("Humanoid") then print("idk") end end)
Click Accept Answer if this was what you were looking for! Comment if you have any more concerns!