Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

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

Asked by 4 days ago
Edited 4 days ago

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

local stats = game.Players.LocalPlayer:findFirstChild("leaderstats")
local cash = stats:findFirstChild("Cash")

cash.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.

2 answers

Log in to vote
0
Answered by 4 days ago
Edited 4 days 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

while true do
    wait(300)
    for _,player in pairs(game.Players:GetPlayers()) do
        if player ~= nil then
            local stats = player:FindFirstChild("leaderstats")
            local cash = stats:FindFirstChild("Cash")
            cash.Value = cash.Value + 100
        end
    end
end

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

0
Worked! Thanks! VikkiVuk 39 — 4d
Ad
Log in to vote
0
Answered by 4 days ago
Edited 4 days ago

Just put this script under the one above:

while true do
      wait(300)
      cash.Value = cash.Value + 100
end

Thats it, hoped it helps.

You can also say

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

Answer this question