Infinite yield possible

Hello, ive made stats which include a health stat and a magic stat however the stats don’t load the actual players stats because I get the error “Infinite yield possible” here’s the code and I was wondering if there’s a fix for this? The MaxMagic and Magic is a number value in the characters Humanoid and I’ve done the same for Health however not a number value as the humanoid already has the health and maxhealth value inside it. It sometimes loads however sometimes doesn’t.

local tweenService= game:GetService("TweenService")

local progress = script.Parent

local MaxMagic = game.Players.LocalPlayer.Character:WaitForChild("Humanoid"):WaitForChild("MaxMagic")
local Magic = game.Players.LocalPlayer.Character:WaitForChild("Humanoid"):WaitForChild("Magic")

local left = progress:WaitForChild("Left"):WaitForChild("Circle")
local right = progress:WaitForChild("Right"):WaitForChild("Circle")
local center = progress:WaitForChild("Centre")

local percentage = Instance.new("NumberValue")
percentage.Parent = script.Parent
percentage.Name = "percentage"
local Text = script.Parent.TextFrame.TextLabel

percentage.Value = Magic

local rotation = math.floor(math.clamp(percentage.Value / MaxMagic.Value * 360, 0, 360))

right.UIGradient.Rotation = math.clamp(rotation, 0, 180)
left.UIGradient.Rotation = math.clamp(rotation, 180, 360)
Text.Text = Magic.Value.." / "..MaxMagic.Value

percentage:GetPropertyChangedSignal("Value"):Connect(function()
	local rotation = math.floor(math.clamp(percentage.Value / MaxMagic.Value * 360, 0, 360))
    Text.Text = Magic.Value.." / "..MaxMagic.Value
	right.UIGradient.Rotation = math.clamp(rotation, 0, 180)
	left.UIGradient.Rotation = math.clamp(rotation, 180, 360)
end)

Magic.Changed:Connect(function()
	percentage.Value = Magic.Value
end)

Infinite Yield Possible means that one of the :WaitForChild() lines at the top is yielding indefinitely because it is not able to find the object referenced.

Please share a screenshot of the error

-- Function to simulate a task that takes time
local function simulateTimeConsumingTask()
    for i = 1, 5 do
        print("Processing step " .. i)
        wait(1) -- Yielding for 1 second (you can adjust the time as needed)
    end
end

-- Coroutine function to run the task
local function runTaskCoroutine()
    print("Task started")
    simulateTimeConsumingTask()
    print("Task completed")
end

-- Connect the coroutine function to a button click
local button = script.Parent

button.MouseButton1Click:Connect(function()
    coroutine.wrap(runTaskCoroutine)() -- Start the coroutine
end)

Looks like it’s unable to find the “Magic” and “MaxMagic” objects within the Humanoid. Ensure that those objects do exist locally when running the game.

1 Like

they definitely do exist however its also happening for Health and MaxHealth even though their properties within the humanoid

You can’t wait for a property, they are inside the Humanoid and are not a child of the Humanoid. (Like are not an object)

“Magic” and “MaxMagic” are not properties though, OP said they are NumberValue objects

1 Like

Check your Humanoid in game and see if they are really parented inside the humanoid. you might’ve put them in the wrong spot

1 Like

How does the Script or LocalScript where you’re creating the Magic and MaxMagic values look like?

sorry I don’t understand what you mean by that ?

Are you using a script to create those number values or are you creating them yourself when play-testing? If you’re creating them yourself then the problem you’re experiencing is because the script is running before you’ve created them and that warning shows up after 5 seconds have passed since the script first attempted to retrieve the value, so if you take longer than 5 seconds to create them it would cause the warning to appear

ah okay thankyou ill create them from the script

1 Like

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