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
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.
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.