Rebirth system help

I’m making a Orange juice tycoon type of game it was going all great and according to plan but when I started working on the Rebirth system I hit a concrete wall, I have no clue how to calculate the amount of rebirths a player can do according to the amount of money they have nor do I have a good formula to calculate the amount of money they should have to do 1 Rebirth

Current code:

	Money.Changed:Connect(function(NewValue)
		if #script.Parent.Buttons:GetChildren() <= 1 then
			numberOfRebirths = NewValue / 5000*PlayerData.Rebirths.Value*(2*PlayerData.Rebirths.Value + PlayerData.Rebirths.Value + 1)
			
			local newPrice = 5000*numberOfRebirths*(2*PlayerData.Rebirths.Value + numberOfRebirths + 1)
			
			info.MFrame.FlavorPrice.Text = newPrice
			rebirthButton.Price.Value = newPrice		
		end
	end)

The number of rebirths value is always more than 1k for some reason and the NewPrice value is extremely high and I’m assuming its because numberofrebirths isnt calculated correctly.

I took the formula from this dev post but I don’t think I’m applying it correctly

Any help is gladly appreciated

1 Like

Try this:

Money.Changed:Connect(function(NewValue)
	if #script.Parent.Buttons:GetChildren() <= 1 then
		local cR = PlayerData.Rebirths.Value
		local nR = PlayerData.Rebirths.Value + 1
		
		local newPrice = (cR * nR + nR * (nR+1) / 2) * 10000
		info.MFrame.FlavorPrice.Text = newPrice
		rebirthButton.Price.Value = newPrice		
	end
end)
1 Like

Is there a way to calculate how many rebirths the player can do according to their money? and not just add 1 to their current rebirth value?

1 Like

Something like this

1 Like

Is there a price you want for each rebirth?

1 Like

That’s my issue the new price depends on the amounts of rebirths

just multiply the current price by the amount of rebirths the player has

1 Like

or you can set a table up with all prices and then when you want to get the price you can index the table via the rebirths value so like

local Costs = {100, 400, 1000, 2000, 5000}

local function getPrice(rebirthAmount)
    return Costs[rebirthAmount]
end

Wouldn’t that mean the game would have a set amount of rebirths and then stop?

1 Like

What would that do, what would it achieve?

No? just add more prices???

2 Likes

or you can do a simple conditions checking if the players rebirths is above the tables length so

local Costs = {100, 400, 1000, 2000, 5000}

local function getPrice(rebirthAmount)
    if rebirthAmount > #Costs then
       return Costs[#Costs]
    else
       return Costs[rebirthAmount]
    end
end

I dont understand how that would fit in my script

1 Like

Using @Katrist reference code I managed to make something similar to what I’m trying to achieve

Here’s the code for anyone looking for a similar effect:

local nextRebirthCost
local currentRebirthCost
local amountOfRebirths = 1
local function ChangeRebirthCost(cR, moneyValue, addValue)
	local baseRebirthAmount = 100000
	local newPrice = (cR * (cR+1) + (cR+1) * (cR+2) / 2) * baseRebirthAmount
	local nextSkip = (cR * (cR+addValue) + (cR+addValue) * (cR+addValue+1) / 2) * baseRebirthAmount
	if moneyValue > nextSkip then
		ChangeRebirthCost(cR, moneyValue, addValue+1)
		amountOfRebirths += 1
	else
		currentRebirthCost = nextSkip
		nextRebirthCost = (cR * (cR+addValue+1) + (cR+addValue+1) * (cR+addValue+2) / 2) * baseRebirthAmount
		return "Cant go no more"
	end
end