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

What is Infinite Yield Possible and How to fix it?

Im new to this and I found a crawl script and the output says: Infinite yield possible on 'ServerScriptService.CrawlServer:WaitForChild("CrawlMove")' How can I fix this?

local rStorage = game:GetService("ReplicatedStorage") local rEvents = rStorage:WaitForChild("RemoteEvents")

game.Players.PlayerAdded:Connect(function(plr) local crawlValue = Instance.new("BoolValue",plr) crawlValue.Value = false crawlValue.Name = "CrawlEnabled"

local char = workspace:WaitForChild(plr.Name)
local human = char:WaitForChild("Humanoid")

local idleLoaded = human:LoadAnimation(script:WaitForChild("CrawlIdle"))
local moveLoaded = human:LoadAnimation(script:WaitForChild("CrawlMove"))

human.Running:Connect(function(speed)
    if speed > 0 and crawlValue.Value == true then
        moveLoaded:Play()
    else
        moveLoaded:Stop()
    end
end)

crawlValue:GetPropertyChangedSignal("Value"):Connect(function()
    if crawlValue.Value == true then
        human.WalkSpeed = 8
       
        idleLoaded:Play()
    else
        human.WalkSpeed = 16
       
        idleLoaded:Stop()
        moveLoaded:Stop()
    end
end)

end)

rEvents.CrawlEvent.OnServerEvent:Connect(function(plr,enabled) local crawlValue = plr:WaitForChild("CrawlEnabled")

crawlValue.Value = enabled

end)

2 comments

1

An infinite yield denotes that the child it's searching for was not found and has taken an unreasonable amount of time to locate; the Script will warn you of a potential scenario where it may hang forever. Check the Instance Name if it is a child of the Script, and make sure there aren't any accidental trailing whitespace characters

0

please accept his answer so it isnt on the front page anymore

2 answers

Starting off, :WaitForChild() yields or waits until the object is loaded in or render. Infinite yield just means that the script might yield or wait forever, but it usually doesn't unless you typed the name of the instance wrong. The infinite yield warning is mostly common on LocalScript's as they load before the server, especially scripts inside ReplicatedFirst.

8 comments

0

Thanks for the reply, do you know what i have to change in my script to fix it?

0

Perhaps put the animations somewhere else such as ServerStorage?

0

thanks but it gave me the same message, if youre free i could invite you as a team dev and you could help me out? thanks for helping though :)

0

Okay, I guess I am quite free so I could help you out.

0

Thanks a ton, i'll message you soon

0

Okay.

0

Ok, sent a friend request

0

I've accepted it.

infinite yield is when :WaitForChild() is not finding an object which causes the script to stop at that spot and wouldn't go on, you might as well define the animations (if you created them in the workspace and not the script) using :FindFirstChild() like this...

local crawlIdle = script:FindFirstChild("CrawlIdle")
local crawlMove = script:FindFirstChild("CrawlMove")
local clawlIdleAnim -- Leaving this nil so that the animation wouldn't be local inside the if
local crawlMove
if crawlIdle then
	crawlIdleAnim = human:LoadAnimation(crawlIdle)
	crawlMoveAnim = human:LoadAnimation(crawlMove)
end

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