--Services

local RunService = game:GetService("RunService")

return function(duration, callback, afterDone)
    local startTim = time()

    local con
    con = RunService.RenderStepped:Connect(function()
        local elapsed = time() - startTim
        local percentage = elapsed / duration

        if percentage >= 1 then
            percentage = 1
        end 

        callback(percentage)
        
        if percentage == 1 then
            con:Disconnect()

            if afterDone then 
                afterDone()
            end
        end
    end)
end 
