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

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

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)

2 comments

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?

0

How would I create Mins in the player object?

1 answer

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)

2 comments

0

Its not working!

0

Oops! I made a mistake sorry, I will fix it

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