How would I make an average amount of money per minute script? - for a tycoon game

So I want to make an “average income per minute” type of thing but I don’t know where to start. I tried looking at this topic but that didn’t help. I just want to find out how to make a script like this, I’m not trying to make a script that auto-farms money while the player is offline.

I don’t know maybe I can do like

while true do
   local income = PUT_NUMBER_HERE --income per second maybe?
   local averageIncome = math.floor(income * 60)
   wait(1)
end

How should I do this?

4 Likes

in saying “average income per minute” are you trying to calculate their average income per minute or actually give them income

4 Likes

I want to just find out how much money they make per minute, I don’t want to give them income.

1 Like

Well you could get how much pay check they get

For example if they made 380 dollars earning each pay for lets say each 5 seconds
you would do maths of 380 times 12, giving you a minute pay of 4560.

^
Further research, you could do the previous paycheck times how many they get in a minute.
This only regards you using maths to + all the payments made in the 60 seconds.

2 Likes

An average is defined as the sum of a set of numbers divided by how many numbers there are. As you’ll want to have the value across a minute (60 seconds), you will need to find your unit average and multiply the result by 60. The reason why you do this is so you can find out the average amount of cash you can make in one second, your unit rate, which is then repeated 60 times to get the average sum across a minute.

Knowing this, the first thing you’ll want to know is what the player currently owns with any upgrades considered. You will need to find the unit income from one operation of your machines. For example, if a dropper gives 10 cash per brick, then your unit is 10. This will be done for every machine and you will also keep track of how many machines you’ve handled so far.

Once you’ve run through all owned machines, you should have a total sum of the money you can get from your machines in one operation as well as how many you’ve accounted for. You will then take that sum and divide it by the number of machines owned to get the average revenue. From there, multiply by 60 and you now have the sum for the average made in a minute.

I don’t know your setup so I can’t provide any code samples but at least the logic behind it. Please let me know if there’s anything wrong with my explanation or if you don’t understand something and I’ll try to explain as best I can. Be forewarned though, I am not at all good at math; simple things are complicated enough for me, lol. :stuck_out_tongue_closed_eyes:

3 Likes

I tried doing this:

while true do
		if script.Parent.Owner.Value ~= nil then
			Income.Value = 0
			wait(5)
			print(Income.Value)
			game.ReplicatedStorage.RemoteEvents.IncomePerMinute:Fire(math.floor(Income.Value * 12), script.Parent.Owner.Value)
		end
	end
game.ReplicatedStorage.RemoteEvents.IncomePerMinute.Event:Connect(function(income, plr)
	if plr ~= nil and income ~= nil then
		local plrGui = plr:WaitForChild("PlayerGui")
		local textLabel = plrGui["Menu/Stats"]:WaitForChild("IncomePerMin")
		if plrGui ~= nil or textLabel ~= nil then
			textLabel.Text = "Cash / min. $"..income
		elseif plrGui == nil or textLabel == nil then
			warn("PLAYER GUI NOT FOUND OR TEXT LABEL NOT FOUND")
		end
	elseif plr == nil or income == nil then
		error("PLAYER NOT FOUND OR INCOME NOT FOUND")
	end
end)

But nothing worked, and also, the part collector stopped working…

for i,v in pairs(script.Parent.Essentials:GetChildren()) do
		local Owner = script.Parent.Owner
		if v.Name == "PartCollector" then
			v.Touched:connect(function(Part)
				if Part:FindFirstChild('Cash') then
					if Owner.Value ~= nil then
						print("Owner found")
						local player = Owner.Value
						local gamepasses = player:WaitForChild("Gamepasses")
						
						if player and gamepasses["Auto Collect Cash"].Value == true then
							local playerMoney = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
							if playerMoney ~= nil then
								playerMoney.Value = playerMoney.Value + (Part.Cash.Value * gamepasses.CashMultiplier.Value)
								Income.Value = Income.Value + (Part.Cash.Value * gamepasses.CashMultiplier.Value)
							end
						elseif player and gamepasses["Auto Collect Cash"].Value == false then
							Money.Value = Money.Value + (Part.Cash.Value * gamepasses.CashMultiplier.Value)
							Income.Value = Income.Value + (Part.Cash.Value * gamepasses.CashMultiplier.Value)
							Debris:AddItem(Part,0.1)
						elseif not player then
							error("Could not find the player")
						end
					else
						error("Owner not found")
					end
				end
			end)
		end
	end

If you are checking for money per minute then you can simply just do

while true do
local Start_Income = game.Players.leaderstats.Cash.Value --for instance I don't know where you store the money
wait(60)
local End_Income = game.Players.leaderstats.Cash.Value
local outputincome = End_Income - Start_Income
print(outputincome) 
end

Edit of course you need to define the player (so I left out the player as I don’t know if you are doing a server script or local script, should be server though)
if it’s local it will be game.Players.LocalPlayer.leaderstats.Cash.Value for instance
if it’s server then you’ll do

game.Players.PlayerAdded:Connect(function(Player)
local Start_Income = Player.leaderstats.Cash.Value --for instance I don't know where you store the money
wait(60)
local End_Income = Player.leaderstats.Cash.Value
local outputincome = End_Income - Start_Income
print(outputincome) 
end)

That would also count for when you buy stuff. If you have 1000 cash, then 55 seconds later you get 1000 more cash and buy something for 500 cash you’d end up with 1500 cash. Then get 20 more cash giving you an income of -520, even though you earned 1020 cash.

I feel like you’ll need to make a separate value then just due to the fact that the Cash will be influenced on what’s bought and made, you could make a value that is only affected by earned and from that you can set it back to 0 every 60 seconds, but everytime the Player gains cash it also gains cash to the other value and will continue to do so for 60 seconds. This means you won’t really need to check the player’s cash value. That’s the only way I can really think of then

local Interval = 1

local Income = {
	Values = 0;
	Total = 0;
	
	PerInterval = 0
}

game:GetService("RunService").Heartbeat:Connect(function(step)
	Income.Values += 1
	Income.Total += step
end)

while wait(Interval) do
	Income.PerInterval = (Income.Total / Income.Values)
	
	print(Income.PerInterval)
	
	Income.Values = 0
	Income.Total = 0
end

I wrote a little something to help anyone understand if they are still looking for a solution to this problem.

Basically, just had a total and keep track of how many items are being collected and every interval just divide the total by however many values were there. That is how you would get income/interval and make it very accurate.