so I'm trying to make a system that gives you 1 money per minute, but I wanted it to work and give you the amount equal to however long they were gone divided by 60, and then rounded down, thus giving me how many minutes they were gone, and I would then give them 1 money for every minute they were gone.
I have the more part of the script written, but the issue I have is that it either doesn't work without having any errors, or it doesn't wait the 60 seconds to give it to me, so I'm stuck getting either nothing, or getting about 10 money per second when I only want 1 money per minute.
this is my code so far (I'm new to scripting so please don't be to harsh on my bad code) :
local players = game:GetService("Players") local playTable = {} local ticktable = {} game.Players.PlayerAdded:Connect(function(player) table.insert(playTable, #playTable+1, player.Name) table.insert(ticktable, #ticktable+1, tick()) end) while true do wait() for table1 = 1, #ticktable, 1 do if tick() - ticktable[table1] == 60 then local payperson = playTable[table1] ticktable[table1] = tick() print("paid ".. payperson) players:WaitForChild(payperson).leaderstats.Money.Value = players:WaitForChild(payperson).leaderstats.Money.Value + 1 end end end
I've put it all inside a script in ServerScriptService. please help me, all I really need to know is how to fix the If statment actually stops the for loop and runs the code inside. Thanks :)
Try this:
local players = game:GetService("Players") local playTable = {} local ticktable = {} game.Players.PlayerAdded:Connect(function(player) table.insert(playTable, #playTable+1, player.Name) table.insert(ticktable, #ticktable+1, tick()) --[[ something for my own debugging, you don't need this bit! local leaders = Instance.new("NumberValue",player) leaders.Name = "leaderstats" local Money = Instance.new("NumberValue",leaders) Money.Name = "Money" ]] end) function math_round(num) return math.floor(num+0.5) end while true do wait() for table1 = 1, #ticktable, 1 do if math_round(tick() - ticktable[table1]) == 60 then local payperson = playTable[table1] ticktable[table1] = tick() print("paid ".. payperson) players:WaitForChild(payperson).leaderstats.Money.Value = players:WaitForChild(payperson).leaderstats.Money.Value + 1 end end end
Just updated this answer with a working script. I must have had a brain fart in thinking tick() was running at 60fps lol my bad!.
the changes i made simply rounds off the tick() as it returns the time in seconds and the mili secs eg:
0.12523526 1.25642321 etc....
so the above if statement will never fire as its looking for exact numbers!.
it Should be working now but if not let me know! :)
It still does nothing in output and doesn't give me money, and I directly copied the code you sent. Is it maybe supposed to have something you forgot to add, or do I need to do something to activate it?