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

Is there a simple explanation on why this script wont run and why it shows infinite yield?

Prints out 'Infinite yield possible on 'Players.10x31x2019:WaitForChild("Character")' did i type anything wrong? I changed it back in forth from "FindFirstChild" to "WaitForChild" Any Solutions?

local player = game.Players.LocalPlayer
local character = player:WaitForChild("Character")
local HumanoidRootPart = character:WaitFirstChild("HumanoidRootPart")

wait(3)
HumanoidRootPart.CFrame = CFrame.new(part.Position)

3 answers

You cannot do WaitForChild on a Character, the reason for this is because the Character just redirects you to the workspace, the WaitForChild is waiting for a descendant named Character to enter it before running the script, i recommend you just do this:

re-written script for you (since yours is causing problems)

game.Players.PlayerAdded:Connect(function(Player)
       Player.CharacterAdded:Connect(function(Character)
         local stoperror = Character:WaitForChild("HumanoidRootPart")
           wait(3)
            Character.HumanoidRootPart.CFrame = workspace.Part.CFrame * CFrame.new(0, 0.5, 0)
 Character:Disconnect()
   end)
end)

2 comments

0

theres another problem 'Players.10x31x2019.PlayerScripts.LocalScript:3: attempt to index nil with 'WaitForChild'

0

Use my second option.

updated the script and theres still another problem 'Players.10x31x2019.PlayerScripts.LocalScript:3: attempt to index nil with 'WaitForChild'

part = workspace.Part
local player = game.Players.LocalPlayer
local HumanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")


wait(5)
HumanoidRootPart.CFrame = CFrame.new(part.Position)

4 comments

0
  1. You posted an answer, refrain from doing so, use comments, however is this a local script? - if not use my second option as a Server Script in ServerScriptService
0

no, and yes it is a local script

0

hangon i'll re-write one in my answer.

0

i've re-written a script, put this in a server script in ServerScriptService.

local character = player.Character or player.CharacterAdded:Wait()

this?

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