#Program not waiting 0.1 seconds between each one

1 messages · Page 1 of 1 (latest)

hollow stump
#
local rs = game:GetService("ReplicatedStorage")
local re = rs.ShowCooldown
local CooldownFrame = rs.Cooldown
local plr = game:GetService("Players").LocalPlayer

function roundNumber(numb)
    print(math.floor(numb * 10) / 10)
    return math.floor(numb * 10) / 10
end

re.OnClientEvent:Connect(function(moveName, cooldown)
    local cooldownX = CooldownFrame:Clone()
    cooldownX.MoveName.Text = moveName

    local count1 = 0
    for i, v in pairs(plr.PlayerGui.Cooldowns:GetChildren()) do
        if v:IsA("Frame") then
            count1 = count1 + 1
        end
    end
    local position = Instance.new("BoolValue")
    position.Name = tostring(count1)
    position.Parent = plr.PlayerGui.Cooldowns.Positions
    cooldownX.AmountWhenAdded.Value = count1 + 1
    cooldownX.Position = UDim2.new(0,25,0.85,-110 * count1)
    cooldownX.Parent = plr.PlayerGui.Cooldowns
    cooldownX.Cooldown.Value = cooldown
    local count = cooldownX.Cooldown.Value
    local Timer = cooldownX.Timer
    local numberToDisplay = nil
    repeat
        numberToDisplay = roundNumber(count)
        Timer.Text = tostring(numberToDisplay)
        task.wait(0.1)
        count = count - 0.1
    until numberToDisplay == 0
    
    if numberToDisplay == 0 then
        cooldownX:Destroy()
    end
end)
#

This is what I've written for it, basically what it does is that after a move is used it fires the server then the server fires this script, it's meant to decrease the timer every 0.1 seconds until it reaches 0, updating the cooldown every time it does so

#

The example I'm using is a 9 second cooldown but in reality the cooldown display is showing a 10.1 second cooldown because of the added milliseconds

#

Was wondering if there was a better method to do this, or if I'm simply just doing something inefficiently here that's throwing it off

mellow wraith
#

but

#

if your using this

#

do it in

#

task.spawn()

#

and create a coroutine

#

instead of using repeat until

#

cuz that's gonna get started again every time that's started

#

like

#

fired

hollow stump
#

I'll try using task.spawn() now, thanks!

mellow wraith
#

np

#

if you need help implementing a modular system lmk