Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)
0
theres another problem 'Players.10x31x2019.PlayerScripts.LocalScript:3: attempt to index nil with 'WaitForChild' 10x31x2019 -6 — 4y
0
Use my second option. GoreDemons 215 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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)
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 GoreDemons 215 — 4y
0
no, and yes it is a local script 10x31x2019 -6 — 4y
0
hangon i'll re-write one in my answer. GoreDemons 215 — 4y
0
i've re-written a script, put this in a server script in ServerScriptService. GoreDemons 215 — 4y
Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago
local character = player.Character or player.CharacterAdded:Wait()

this?

Answer this question