#task.wait() taking more time than it should or something i dont understand

1 messages · Page 1 of 1 (latest)

simple ice
#

the photo is the output and the 1st line is how long the rolling animation should take and its done by task.wait() and the 2nd line is the time that the animation took for the player

#

this is the code:

function Roll.OnPress()
    if Debounce1 then
        Debounce1 = false
        local TimeWaited = 0
        local TimeWhenPressed = tick()
        
        AnimationFrame.Button.Activated:Connect(function()
            if Debounce1 == true then
                AnimationFrame.Visible = false
            end
        end)
        
        coroutine.wrap(Cooldown)()
        
        for i = 0, 2, 0.1 do
            local FakeResult = RollFunction:InvokeServer(1, ResourceCrate[1].Threshold, ResourceCrate, 2.5)
            local Factor = ((1.5^i*0.3-0.3) / RollSpeed)
            
            Sounds.RollingSound:Play()
            AnimationRoll(FakeResult)
            
            task.wait(Factor)
            TimeWaited += Factor
        end
        
        
        local RollResult = RollFunction:InvokeServer(1, ResourceCrate[1].Threshold, ResourceCrate, 2.5)
        task.wait(0.4 / RollSpeed)
        TimeWaited += (0.4 / RollSpeed)
        
        AnimationRoll(RollResult)
        print(TimeWaited.." seconds for the rolling animation to stop")
        
        local DeltaTime = tick() - TimeWhenPressed
        print(DeltaTime .. " seconds that actually took for the palyer for the rolling to stop")
        
        AddInventory:Fire(RollResult, 1)
    else
        return    
    end
end```
#

i want to just decrease as much as possible the time between the two outputs

#

this is a local script btw

acoustic bluff
#

@simple ice is that even possible

simple ice
#

or maybe there is too much functions in the for loop that it gets overwhelmed and takes time to do them

errant monolith
simple ice
#

the time between the outputs is 0.3 seconds which is way better than the 1.5 seconds in the screenshot above

#

ty!