WaitForChild not wait

player.Character:WaitForChild("HumanoidRootPart").CFrame = game.Workspace.yeshere.CFrame
player.Character:WaitForChild("HumanoidRootPart").Anchored = true

I made it to move player to particular position.
It works when player respawn, so HumanoidRootPart should also born in a few second but…
image
It doesnt wait for it. I have never used WaitForChild in myself. Pls teach me what I didnt know

2 Likes

Based on what you have here, it seems that Player.Character is nil when you try to run :WaitForChild(). Try adding the following line before those other two:

while not player.Character do task.wait() end`
3 Likes

You need to wait for the character too. Because the character hasn’t loaded so the humanoidrootpart doesn’t exist either

1 Like

I changed code simply like it. I didnt know the Character model is removed also when I die

player:WaitForChild("Character").HumanoidRootPart.CFrame = game.Workspace.yeshere.CFrame
player:WaitForChild("Character").HumanoidRootPart.Anchored = true

and this error appeard

  • Infinite yield possible on ‘Players.Player1:WaitForChild(“Character”)’
2 Likes

And I also changed mine like you,

while not player.Character do
	task.wait()
end
player.Character:WaitForChild("HumanoidRootPart").CFrame = game.Workspace.yeshere.CFrame
player.Character:WaitForChild("HumanoidRootPart").Anchored = true

It worked well!
But why the code upper not worked?

And addly, Can I apply WaitForChild in here?

game.Players.LocalPlayer.plrewe.Changed:Connect(nilgara)
-> game.Players.LocalPlayer:WaitForChild("plrewe").Changed:Connect(nilgara)

This is localscript and localplayer always exists I think. “plrewe” is playervalue.
I wonder I can put it in Connecting for function.

Sorry for more questions.

2 Likes

Player:WaitForChild("Character") doesn’t work because Character is a property of Player (that refers to the player’s character model), not a child. :WaitForChild("Character") attempts to wait for an instance called “Character” to load or appear, but since neither ever happen, the script gets stuck yielding forever.

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.