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

Why isn't my seat function returning "Seat Occupied" when it is sit on?

When I get on the seat, it prints Humanoid, then when I jump off of it, it prints nil then Seat Occupied. How do I get it to print "Seat Occupied" when I sit on it?

	seat.Changed:connect(function()
		print(seat.Occupant)
		if seat.Occupant == Humanoid then
			print("Seat Occupied")
		end
	end)

2 comments

0

What is Humanoid defined as?

0

When I sit in the seat, the value of Occupant is "Humanoid"

1 answer

✓ Accepted answer

Hi Coos,

It doesn't print "Seat Occupied" because the Occupant is an object property. So, if Humanoid is a variable that is set to the string "Humanoid" then, it won't print because the Occupant is actually an object. If you however check seat.Occupant.Name == "Humanoid" then it would work, or seat.Occupant:IsA("Humanoid") then it may work. Also, I'm not sure if you defined what Humanoid is above in the script. Hopefully you also defined seat.

####So, it would look something like this:

local seat = script.Parent;

seat.Changed:Connect(function()
    print(seat.Occupant)
    if seat.Occupant:IsA("Humanoid") then
        print("Seat Occupied")
    end
end)

##Hope i helped and have a wonderful day/night.

Thanks,

Best regards,

~~ KingLoneCat

2 comments

0

Using IsA to check if an object is of that ClassName isn’t a good idea. IsA returns not only that class, but also classes that inherit from it. If a class that inherits from Humanoid is sitting on the seat, it will also run code.

0

First off, IsA returns a boolean value. It checks if the object is of the class specified in the parameter or if it inherits from that class, but seeing as no class inherits Humanoid, it's perfectly safe to use IsA since it would only return true if it's a Humanoid.

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