WaitForChild breaks code

I get this error that breaks my code:
Infinite yield possible on ‘Players.Ryguy903.Backpack:WaitForChild(“HumanoidRootPart”)’

And the line in question is

local spawnPos = CFrame.new(character:WaitForChild("HumanoidRootPart").CFrame.Position)

What does Backpack have to do with anything? How can I fix it so this does not happen?

1 Like

The most probable reason is that character variable is not a reference of the character model, and something related with the backpack. Show the rest of the code

1 Like

This is true. The script is in a frisbee tool and I get character from this

	local character=frisbee.Parent

Since it first gets in the Player’s Backpack the character reference is a… Backpack. Add another .Parent if it is in StarterPack.

1 Like

Yes thats the issue that variable character is referencing the .Parent of the frisbee, which is not the character is the backpack

1 Like

Right now it is in StarterPack for testing purposes, but I plan on disabling the backpack eventually so when the player pick its up, they can’t drop it.

Then yield the code until Frisbee.Parent is a valid Character or Backpack.

2 Likes

Thats a local script or server one?
You should get the character in a different way if you want to get it when the tool is equipped. By using maybe the equipped method

Server. It seems like the reply above you should work

1 Like

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