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

Payday pays every sec whether then every 180 seconds how can I fix this?

Asked by 9 years ago

Ok so the Payday script works (Thanks Goulstem for getting it to work) but it adds money every second whether then every whatever second it's at example 180 seconds. Also how can I show mins, hours and secs?

local time = 180

while wait(1) do
    time = time - 1
    if (time <= 0) then
        time = 180
    end
    for i,v in pairs(game.Players:GetPlayers()) do
        --different source directory
        local plr = game.ServerScriptService.Players:FindFirstChild(v.Name)
        if plr then
            --edit--
            local gui = v.PlayerGui:FindFirstChild('PaydayGui')
            --edit--
            local creds = plr.Tickets
            if gui then
                gui.Label.Text = 'Next payday in '..time..' seconds'
            end
            if v:IsInGroup(782018) then
                creds.Value = creds.Value + 50
            elseif v:IsInGroup(234706) then
                creds.Value = creds.Value + 30
            end
            creds.Value = creds.Value + 50
        end
    end
end

1 answer

Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

To make it so it only awards you every x amount of seconds, you need to put the code inside your conditional on line 5. This way, it will count down and only award if the timer is at 0, then reset.


And sorry, i'm not going to answer about how to convert it to minutes / hours because that's not constructive on your part if I just do it for you.


local time = 180

--Make a function to award.

function awardPlayers()
    for i,v in pairs(game.Players:GetPlayers()) do
        local plr = game.ServerScriptService.Players:FindFirstChild(v.Name)
        if plr then
            local creds = plr.Tickets
            if v:IsInGroup(782018) then
                creds.Value = creds.Value + 50
            elseif v:IsInGroup(234706) then
                creds.Value = creds.Value + 30
            end
            creds.Value = creds.Value + 50
        end
    end
end

--Make a function to update the guis

function updateGuis()
    --Get all players
    for i,v in pairs(game.Players:GetPlayers()) do
        --Get gui
        local gui = v.PlayerGui:FindFirstChild('PaydayGui')
        --Make sure gui is there
        if gui then
            --Update it
            gui.Label.Text = 'Next payday in '..time..' seconds.'
        end
    end
end

while wait(1) do
    time = time - 1
    --Update the guis
    updateGuis()
    if time <= 0 then
        time = 180
        --Award the players INSIDE the conditional.
        awardPlayers()
    end
end
0
That's fine and thx for fixing it again! :) Anciteify 70 — 9y
0
No problem. Goulstem 8144 — 9y
0
Exactly now it's not working it's not showing any error what so ever o.O Anciteify 70 — 9y
0
What do you mean by conditional? Anciteify 70 — 9y
View all comments (5 more)
0
Nvm I understand now :P Anciteify 70 — 9y
0
Sorry, it's going to award you after 180 seconds but it's not going to show the countdown on players' leaderboards. It's because it's not updating the guis in the while loop. I'll edit it. Goulstem 8144 — 9y
0
ah awesome thx so much! Anciteify 70 — 9y
0
Should work nao c: Goulstem 8144 — 9y
0
It does thx so much! Anciteify 70 — 9y
Ad

Answer this question