-
I want to calculate the requirement needed to prestige and reincarnate. Currently I am using a loop to do that when calculating multi-prestige/reincarnation
-
It works just fine until the numbers get really big. Then the lag starts and when a player wants to prestige 1 million times, things stop working and I get the error message
Script timeout: exhausted allowed execution time
-
I have tried varies formulas to find out how to calculate the requirement without the need for a loop, but have been unsuccessful.
The original Prestige formula when a player wants to prestige just one time is:
requirement = 1000000*(currentPrestige.Value+1)
The original Reincarnation forumla when a player wants to reincarnate just one time is:
requirement = 15*(currentReincarnation.Value+1)
Here is the loop I use when a player wants to prestige multiple times at once
function module.MultiRebirthReq(plr, rebirth, num)
local plrStats = plr:WaitForChild("PlayerStats")
local reincarnation = plrStats.Reincarnation
local calc = plrStats.Prestige.Value+1
local reincarnationCalc = plrStats.Reincarnation.Value+1
local requirement = 0
if rebirth == "Prestige" then
for count = 1, num do
requirement = requirement+(1000000*(calc))
calc = calc+1
end
elseif rebirth == "Reincarnation" then
for count = 1, num do
requirement = requirement+(15*(reincarnationCalc))
reincarnationCalc = reincarnationCalc+1
end
end
return requirement
end
Maybe someone here has a better understanding of math and can guide me to a more efficient formula that does not need a loop or perhaps there is a way to avoid the lag/crash/time out issue in some other way