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

Fix script exhaustion allowed execution time?

game.Players.PlayerAdded:Connect(function(player)
	while true do
		if player:WaitForChild("PlayerData"):WaitForChild("xpProg").Value == player:WaitForChild("PlayerData"):WaitForChild("xpReq").Value then
			player.PlayerData.xpProg.Value = 0
			player.PlayerData.xpReq.Value = player.PlayerData.xpReq.Value * 2 + 1000
			player.leaderstats.Level.Value = player.leaderstats.Level.Value + 1
		end
	end
end)

This is a script that when a player reaches the required xp to level, reset xpProg and set xpReq to be higher. However, when I try and test the script in studio, the client freezes and errors in output with script exhaustion: allowed execution time and leads me to line 5. How do I fix this, since I don't know how.

1 comment

0

no wait(), put one after line 2

1 answer

✓ Accepted answer

really simple fix, just add a Wait.

here:

game.Players.PlayerAdded:Connect(function(player)
    while true do
        if player:WaitForChild("PlayerData"):WaitForChild("xpProg").Value == player:WaitForChild("PlayerData"):WaitForChild("xpReq").Value then
            player.PlayerData.xpProg.Value = 0
            player.PlayerData.xpReq.Value = player.PlayerData.xpReq.Value * 2 + 1000
            player.leaderstats.Level.Value = player.leaderstats.Level.Value + 1
	    wait()
        end
    end
end)

3 comments

0

I put wait(1), it fixes it but still leaves a bit of a lag spike. How do I fix this?

0

Nevermind, I just had to put it on a different line.

0

instead of while true do, try while wait() do (replace it with while true do) and remove the wait at line 7. Tell me if it works

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