How can I make a progressive loop?

Hello, I am doing a simulator, and I am doing the rebirth system, but I don’t know how I can make a loop increase the amount of points needed to do the rebirth.
Please help me, Thank you.
The code I have so far:

game.ReplicatedStorage.RebirthEvent.OnServerEvent:connect(function(player)
	if player.leaderstats.rebirths.Value == 0 then
		if player.leaderstats.Points.Value >= 5000 then -- strength needed to rebirth
			player.leaderstats.rebirths.Value = player.leaderstats.rebirths.Value +1
			player.leaderstats.Points.Value = 0
	end

	end
	
	
end)
1 Like

I don’t understand what exactly you want to do. Could you provide details?

I want to make every time I rebirth raise the amount of points needed to get rebirth.

You could “harcode” it in a table, like so:

local rebirthPointCost = {
    [1] = 5000,
    [2] = 10000,
    [3] = 20000,
    [4] = 50000,
}

You could also write the table like so:

local rebirthPointCost = { 5000, 10000, 20000, 50000 }

But that makes it less readable IMO.

You can then set up your rebirth code like this:

game.ReplicatedStorage.RebirthEvent.OnServerEvent:connect(function(player)
	local rebirths = player.leaderstats.rebirths
	local points = player.leaderstats.Points
	local rebirthPointCost = rebirthPointCosts[rebirths.Value + 1]

	if rebirthPointCost then
		if points.Value >= rebirthPointCost then
			rebirths.Value += 1
			points.Value = 0
		end
	else
		warn(("No rebirth cost coded for rebirth number %d, cannot rebirth!"):format(rebirths.Value + 1))
	end
end)

Another approach is to use a mathematical function, like an exponential or power function. This has the advantage that in most cases you can evaluate the function at any rebirth number, so you can potentially have infinite rebirths with costs that keep growing.

E.g. here’s the function (50x)^2

And the code to use it could look like this:

game.ReplicatedStorage.RebirthEvent.OnServerEvent:connect(function(player)
	local rebirths = player.leaderstats.rebirths
	local points = player.leaderstats.Points
	local rebirthPointCost = (50 * (rebirths.Value + 1))^2

	if rebirthPointCost then
		if points.Value >= rebirthPointCost then
			rebirths.Value += 1
			points.Value = 0
		end
	else
		warn(("No rebirth cost coded for rebirth number %d, cannot rebirth!"):format(rebirths.Value + 1))
	end
end)

I recommend using some kind of graphing software to play around with and tweak different functions to get progressions that you like.

What you do is: You record how many times you rebirth in a leaderboard variable, and then you times that by the amount it takes to originally rebirth for the first time so if you need 5000 points to rebirth, you times that by the number of rebirths you currently have plus 1.

game.ReplicatedStorage.RebirthEvent.OnServerEvent:connect(function(player)
local points = 5000
for i = 0, 50, 1 do
		if player.leaderstats.Points.Value >= points then -- strength needed to rebirth
			player.leaderstats.rebirths.Value = player.leaderstats.rebirths.Value +1
			player.leaderstats.Points.Value = 0
			points = points + 15000
		end
	end
end)

Will this do?

Price will increase x2 every rebirth

game:GetService("ReplicatedStorage").RebirthEvent.OnServerEvent:Connect(function(player)
	local rebirths = player.leaderstats.rebirths.Value
	local pointsNeed = 5000
	for i = 1, rebirths do
		pointsNeed *= 2
	end
	if player.leaderstats.Points.Value >= pointsNeed then
		rebirths += 1
		player.leaderstats.Points = 0
	end
end)

I already solved it myself, thanks for the help anyway.