Infinite yield on humaniod

I’m making a spaceship game but I need to identify humanoid but I get an infinite yield?
I want so if a player is seated in the verchileseat it will cancolide it true then when there is no one it turns to false.
i have attempted…

local character = game.StarterPlayer.StarterCharacterScripts
local humanoid = character:WaitForChild("humanoid")
local door = script.Parent.Parent.Door

function seat()
	if humanoid.sit == true
	then
		door.Part1.CanCollide = true
		door.Part2.CanCollide = true
		door.Part3.CanCollide = true
		
	else
		if humanoid.sit == false
			then

I get an infinite yield, what do i fix???.

1 Like

I’d suggest to replace This:

local humanoid = character:WaitForChild("humanoid")

to this:

local humanoid = character:WaitForChild("Humanoid")

Maybe the problem exists, because the H was lowercase.

Your character isn’t in theStarterCharacterScripts

i tried but is still get the yield

its ment to be a ship to be bought at a store, then copied into a player inventory where they can release it.

Still, that’s not how you get the Character. To get the character from LocalPlayer, you can doLocalPlayer.Character or put the script in StarterCharacterScripts.

how would this work? such as if copied 20 times the script has to be separate and not one person operating all the ships (scripts)

StarterCharacterScripts is a child of Game, it will never contain a Humanoid, so that’s where you’re getting an infinite yield from.

In a LocalScript, you can just use Game.Players.LocalPlayer.Character to get the local Character and thus the Humanoid.

In a server Script, you can use the following method:

local character
local humanoid

script.AncestryChanged:Connect(function(child, parent)
	character = script.parent
	humanoid = character:WaitForChild("Humanoid")
end)
-- continue code

This will leave the original code in StarterCharacterScripts unchanged.

I suggest instead of doing that doing the following:
Detecting for a player to join → detecting if their character loads (on a server script)