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

My countdown does not work correctly, can you help me?

Asked by 6 years ago

Hello ScriptingHelpers! My countdown does not work correctly, The only thing he sent me is '0:03'... So if you think you can fix it or put me in the right direction I will be very grateful to you!

ModuleScript:

local GameModule = {}

function GameModule:timerConverter(i)
    local t = tostring(i)
    if #t >= 60 then
        local important = (#t - 60)
        return "1:"..(important)
    elseif #t < 60 and #t >= 10 then
        local important = (#t)
        return 0, "0:"..(important)
    elseif #t < 10 and #t > 0 then
        local important = (#t)
        return "0:0"..(important)
    else
        return i
    end
end

return GameModule

Script:

function msgAll(title, i)
    for _,p in ipairs(game.Players:GetChildren()) do
        if p:FindFirstChild('PlayerGui') ~= nil and p.PlayerGui:FindFirstChild('GameGui') ~= nil then
            p.PlayerGui.GameGui.GameStatus.Timer.Text = GameModule:timerConverter(i)
            p.PlayerGui.GameGui.GameStatus.Timer.Title.Text = title
        end
    end
end

while wait() do
    for i = 60, 1, -1 do
        title = 'Intermission'
        print(i)
        msgAll(title, i)
        wait(1)
    end
end

Error: No error ressensed. Everything works but not as it should be.

1 answer

Log in to vote
1
Answered by
blowup999 659 Moderation Voter
6 years ago
Edited 6 years ago

In your function timerConverter you convert the seconds passed into a string. So when you do #t you're just getting the length of the string. Since you're getting the length of the string and it's from 60 down to 1 the string should always return #t == 2 or #t == 1. Because of this it will always run the elseif #t < 10 and #t > 0 then

So to fix it you should just use the variable i in the module script instead of converting it to t, or do t = i.

Ad

Answer this question