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

Why does my script error out on line 4?

I have my script to where if the object touching the part is a hat then end the script else if it has a humanoid then teleport it into the house

here's my house

script.Parent.Touched:connect(function(hit)
	if hit.Parent.Name == "Hat" then
	print'nope'
	elseif hit.Parent.Humanoid then
local h = game.Players:findFirstChild(hit.Parent.Name)
h.PlayerGui.Enter.Frame.Visible = true
h.PlayerGui.Enter.Button.Visible = true
else
	end
end)

1 answer

✓ Accepted answer

It looks like you want to see if there is an instance called "Humanoid" as a child of hit.Parent. You want your condition hit.Parent.Humanoid to return nil if there is no humanoid there, but it's not actually safe to do this and an error will be thrown if there is no humanoid. Rather, hit.Parent:FindFirstChild("Humanoid") will do what you want, returning the Humanoid if it can be found, and nil otherwise.

1 comment

0

Oh hey defaultio and thanks

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