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
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)
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