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)
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
.
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