Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Lua Scripting | Trying to give an player cash every 5 minutes. Help?

Asked by 4 years ago
Edited 4 years ago

Hey, so, im trying to make it that every player online gets 100 cash every 5 minutes, i tried doing something like

1local stats = game.Players.LocalPlayer:findFirstChild("leaderstats")
2local cash = stats:findFirstChild("Cash")
3 
4cash.Value = cash.Value + 100

but that didnt work, and yet i dont even know how to make it every 5 minutes or so. And im kinda new to roblox scripting, so i dont know some things. I mean it doesnt have to be 5 minutes, i just want to give them some cash. So you dont have to answer it with 5 minutes thing, just tell me how to give them cash.

0
Hello, I know I'm just a bit late(by 2 years) but, I have a good script for just that.              local Amount = 100local TimeDelay = 300local CurrencyName = "Coins"while true do wait(TimeDelay) for i, v in pairs(game.Players:GetPlayers()) do if v:FindFirstChild("leaderstats") then v.leaderstats[CurrencyName].Value = v.leaderstats[CurrencyName].Value + Amount end endend Poopoobob13 0 — 2y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You can put it in a while true do loop, iterate through every player in the game and give them the money. You let the while true do loop run every 300 seconds which is 5 minutes of course EXAMPLE

01while true do
02    wait(300)
03    for _,player in pairs(game.Players:GetPlayers()) do
04        if player ~= nil then
05            local stats = player:FindFirstChild("leaderstats")
06            local cash = stats:FindFirstChild("Cash")
07            cash.Value = cash.Value + 100
08        end
09    end
10end

Hopefully this works (Btw this is if you are going to use a server-sided script)

0
Worked! Thanks! VikkiVuk 74 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Just put this script under the one above:

1while true do
2      wait(300)
3      cash.Value = cash.Value + 100
4end

Thats it, hoped it helps.

You can also say

1while 1+1==2 do
2      wait(300)
3      cash.Value = cash.Value + 100
4end

Answer this question