While shortcut for function help

Hello! I’m trying to make this function automatic with a “while” but idk how to make it work… Do you guys have any idea?

			
			['unlockPurchases'] = {
				{rebirthCount = 1,unlock = "rebirth1"},
				{rebirthCount = 2,unlock = "rebirth2"},
				{rebirthCount = 3,unlock = "rebirth3"},
				{rebirthCount = 4,unlock = "rebirth4"},
				{rebirthCount = 5,unlock = "rebirth5"},
				{rebirthCount = 6,unlock = "rebirth6"},
				{rebirthCount = 7,unlock = "rebirth7"},
				{rebirthCount = 8,unlock = "rebirth8"},
				{rebirthCount = 9,unlock = "rebirth9"},
				{rebirthCount = 10,unlock = "rebirth10"},
				{rebirthCount = 11,unlock = "rebirth11"},
				{rebirthCount = 12,unlock = "rebirth12"},
				{rebirthCount = 13,unlock = "rebirth13"},
				{rebirthCount = 14,unlock = "rebirth14"},
				{rebirthCount = 15,unlock = "rebirth15"},
				{rebirthCount = 16,unlock = "rebirth16"},
				{rebirthCount = 17,unlock = "rebirth17"},
				{rebirthCount = 18,unlock = "rebirth18"},
				{rebirthCount = 19,unlock = "rebirth19"},
				{rebirthCount = 20,unlock = "rebirth20"},
				{rebirthCount = 21,unlock = "rebirth21"},
				{rebirthCount = 22,unlock = "rebirth22"},
				{rebirthCount = 23,unlock = "rebirth23"},
				{rebirthCount = 24,unlock = "rebirth24"},
				{rebirthCount = 25,unlock = "rebirth25"},
				{rebirthCount = 26,unlock = "rebirth26"},
				{rebirthCount = 27,unlock = "rebirth27"},
				{rebirthCount = 28,unlock = "rebirth28"},
				{rebirthCount = 29,unlock = "rebirth29"},
				{rebirthCount = 30,unlock = "rebirth30"},
				{rebirthCount = 31,unlock = "rebirth31"},
				{rebirthCount = 32,unlock = "rebirth32"},
				{rebirthCount = 33,unlock = "rebirth33"},
				{rebirthCount = 34,unlock = "rebirth34"},
				{rebirthCount = 35,unlock = "rebirth35"},
				{rebirthCount = 36,unlock = "rebirth36"},
				{rebirthCount = 37,unlock = "rebirth37"},
				{rebirthCount = 38,unlock = "rebirth38"},
				{rebirthCount = 39,unlock = "rebirth39"},
				{rebirthCount = 40,unlock = "rebirth40"},
				{rebirthCount = 41,unlock = "rebirth41"},
				{rebirthCount = 42,unlock = "rebirth42"},
				{rebirthCount = 43,unlock = "rebirth43"},
				{rebirthCount = 44,unlock = "rebirth44"},
				{rebirthCount = 45,unlock = "rebirth45"},
				{rebirthCount = 46,unlock = "rebirth46"},
				{rebirthCount = 47,unlock = "rebirth47"},
				{rebirthCount = 48,unlock = "rebirth48"},
				{rebirthCount = 48,unlock = "rebirth49"},
				{rebirthCount = 50,unlock = "rebirth50"},
				{rebirthCount = 51,unlock = "rebirth51"},
				{rebirthCount = 52,unlock = "rebirth52"},
				{rebirthCount = 53,unlock = "rebirth53"}
			},
			
			['defaultCashNeededForRebirth'] = 0,
			['cashNeededForRebirth'] = {
				{rebirthCount = 1,cashAmount = 0},
				{rebirthCount = 2,cashAmount = 150000},
				{rebirthCount = 3,cashAmount = 180000},
				{rebirthCount = 4,cashAmount = 210000},
				{rebirthCount = 5,cashAmount = 260000},
				{rebirthCount = 6,cashAmount = 310000},
				{rebirthCount = 7,cashAmount = 380000},
				{rebirthCount = 8,cashAmount = 450000},
				{rebirthCount = 9,cashAmount = 550000},
				{rebirthCount = 10,cashAmount = 650000},
				{rebirthCount = 11,cashAmount = 770000},
				{rebirthCount = 12,cashAmount = 920000},
				{rebirthCount = 13,cashAmount = 1100000},
				{rebirthCount = 14,cashAmount = 1300000},
				{rebirthCount = 15,cashAmount = 1600000},
				{rebirthCount = 16,cashAmount = 2400000},
				{rebirthCount = 17,cashAmount = 3600000},
				{rebirthCount = 18,cashAmount = 4000000},
				{rebirthCount = 19,cashAmount = 5000000},
				{rebirthCount = 20,cashAmount = 6000000},
				{rebirthCount = 21,cashAmount = 7000000},
				{rebirthCount = 22,cashAmount = 8000000},
				{rebirthCount = 23,cashAmount = 9000000},
				{rebirthCount = 24,cashAmount = 10000000},
				{rebirthCount = 25,cashAmount = 11000000},
				{rebirthCount = 26,cashAmount = 12000000},
				{rebirthCount = 27,cashAmount = 13000000},
				{rebirthCount = 28,cashAmount = 14000000},
				{rebirthCount = 29,cashAmount = 15000000},
				{rebirthCount = 30,cashAmount = 16000000},
				{rebirthCount = 31,cashAmount = 17000000},
				{rebirthCount = 32,cashAmount = 18000000},
				{rebirthCount = 33,cashAmount = 20000000},
				{rebirthCount = 34,cashAmount = 22000000},
				{rebirthCount = 35,cashAmount = 24000000},
				{rebirthCount = 36,cashAmount = 26000000},
				{rebirthCount = 37,cashAmount = 28000000},
				{rebirthCount = 38,cashAmount = 30000000},
				{rebirthCount = 39,cashAmount = 32000000},
				{rebirthCount = 40,cashAmount = 34000000},
				{rebirthCount = 41,cashAmount = 36000000},
				{rebirthCount = 42,cashAmount = 38000000},
				{rebirthCount = 43,cashAmount = 40000000},
				{rebirthCount = 44,cashAmount = 42000000},
				{rebirthCount = 45,cashAmount = 44000000},
				{rebirthCount = 46,cashAmount = 46000000},
				{rebirthCount = 47,cashAmount = 48000000},
				{rebirthCount = 48,cashAmount = 50000000},
				{rebirthCount = 49,cashAmount = 52000000},
				{rebirthCount = 50,cashAmount = 54000000},
				{rebirthCount = 51,cashAmount = 56000000},
				{rebirthCount = 52,cashAmount = 58000000},
				{rebirthCount = 53,cashAmount = 60000000},
			
			},

If anybody goes to 1000 rebirths i don’t want to write 1000 lines for it… You know what i mean.

If you want to automate it, you’re going to need a valid rate of change that you can formulate through code. In the current code, I see that all of the cash amounts are basically random increases from before, not a fixed rate of increase or anything that can really be formulated.

I could change the prices easily to be something fixed like cashamount = cashamount * 1.2 but that’s not the problem. Idk how to make the code create more rebirthcounts and increase them.

local INCREASE_RATE = 150000

local function getNextRebirthData(currentRebirth)
    local nextRebirth = currentRebirth + 1
    return {Money = INCREASE_RATE * nextRebirth, Unlock = "rebirth"..nextRebirth}
end

local currentRebirth = 2
print(getNextRebirthData(currentRebirth))

This is an example of what you could and would work for any rebirth level.

2 Likes

This code looks really good, thank you so much! I’m having trouble where to put it thou… I’ve tried everywhere but idk if it fits my code. I’ve put all the code down below, do you have any idea where or if it might go in?


local Settings = {
		 ['Save'] = {
			['databaseName'] = "curgaoz2", --Change to have new saves --original name ZednovTycoon101
			
			['giveCashToPlayersInGroup'] = { --Will only be given once to new players if they joined the group
			['groupId'] = 12524604, --Id of the group they must join to get cash
				['cashAmount'] = 10000  --The amount of cash they will get
			}
		 },
		 
		 ['Test'] = {
			['showTouchTycoonButtonsGuiOutsideStudio'] = false --Of true will show it when someone plays your game outside studio
		 },     
	
         ['Rebirth'] = {
            ['enabled'] = true,
		['ignorePurchases'] = {"NameOfPurchase1","PurchaseName","NameOfAPurchase",},
            ['resetCash'] = true,
  
			['teleportToo'] = "TeleportPart", --Name of part here but part must be inside each tycoon
			
			['unlockPurchases'] = {
				{rebirthCount = 1,unlock = "rebirth1"},
				{rebirthCount = 2,unlock = "rebirth2"},
				{rebirthCount = 3,unlock = "rebirth3"},
				{rebirthCount = 4,unlock = "rebirth4"},
				{rebirthCount = 5,unlock = "rebirth5"},
				{rebirthCount = 6,unlock = "rebirth6"},
				{rebirthCount = 7,unlock = "rebirth7"},
				{rebirthCount = 8,unlock = "rebirth8"},
				{rebirthCount = 9,unlock = "rebirth9"},
			},
			
			['defaultCashNeededForRebirth'] = 0,
			['cashNeededForRebirth'] = {
				{rebirthCount = 1,cashAmount = 0},
				{rebirthCount = 2,cashAmount = 15000},
				{rebirthCount = 3,cashAmount = 18000},
				{rebirthCount = 4,cashAmount = 21000},
				{rebirthCount = 5,cashAmount = 26000},
				{rebirthCount = 6,cashAmount = 31000},
				{rebirthCount = 7,cashAmount = 38000},
				{rebirthCount = 8,cashAmount = 45000},
				{rebirthCount = 9,cashAmount = 55000},
				{rebirthCount = 10,cashAmount = 65000},
			},
			
		    ['playerRespawned'] = { --Will execute after player spawned
				{
					rebirthCount = 1,
					function(player) 
						--player.Character.Humanoid.WalkSpeed = 35
						--code here to execute if player reached the rebirthCount or above.
					end
				},
				{
					rebirthCount = 2,
					function(player) 
						--player.Character.Head.Transparency = 1
						--code here to execute if player reached the rebirthCount or above.
					end
				}
		    },
		
		   ['playerReachedRebirthCount'] = { --Will only run one time
				{
					rebirthCount = 1,
					function(player) 
						--code here to execute only once if player reached the rebirthCount.
					end
				},
				{
					rebirthCount = 2,
					function(player) 
						--code here to execute only once if player reached the rebirthCount.
					end
				}
		  }
		
     }
}

return Settings


Well, I don’t think it would go into your settings file. You can put the function I gave you anywhere and when they rebirth, you can call the function with the rebirth count.

1 Like