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

This script will not work due to Infinite Yield. Any way to fix it?

Asked by 3 years ago

When I run the command its suppose to exchange your points for minutes but instead I get

Infinite yield possible on 'Players.vhixloqan:WaitForChild("Mins")'

I really need help because I have no idea how to fix this.

game.Players.PlayerAdded:Connect(function(player)

    local leaderstats = player:WaitForChild("leaderstats")
    local Mins = player:WaitForChild("Mins")
    local Tokens = player:WaitForChild("Tokens")

    player.Chatted:Connect(function(msg)
        if player:GetRankInGroup(3942568) >=20 then
            if msg == ";exchange tokens" then

                if leaderstats.Tokens.Value >= 100 then
                    leaderstats.Tokens.Value = leaderstats.Tokens.Value - 100
                    Mins.Minutes.Value = Mins.Minutes.Value + 120
                end


            end
        end
    end)
end)
0
This means that it cannot find anything named "Mins" inside the player object and it's going to yield the script until it exists. Are you sure there is something named "Mins" being created inside the player object? xInfinityBear 1777 — 3y
0
How would I create Mins in the player object? vhixloqan 2 — 3y

1 answer

Log in to vote
0
Answered by
bailley5 114
3 years ago
Edited 3 years ago

I see what your mistake is, you are waiting for Mins and Tokens to be inside the player, not the leaderstats folder.

Here is the fixed version:

game.Players.PlayerAdded:Connect(function(player)

    local leaderstats = player:WaitForChild("leaderstats")
    local Mins = leaderstats:WaitForChild("Mins")
    local Tokens = leaderstats:WaitForChild("Tokens")

    player.Chatted:Connect(function(msg)
        if player:GetRankInGroup(3942568) >=20 then
            if msg == ";exchange tokens" then

                Tokens.Value >= 100 then
                    Tokens.Value = leaderstats.Tokens.Value - 100
                    Mins.Value = Mins.Value + 120
                end


            end
        end
    end)
end)
0
Its not working! vhixloqan 2 — 3y
0
Oops! I made a mistake sorry, I will fix it bailley5 114 — 3y
Ad

Answer this question