#task.wait() taking more time than it should or something i dont understand
1 messages · Page 1 of 1 (latest)
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
@simple ice is that even possible
i think there is lag with the player or smth
or maybe there is too much functions in the for loop that it gets overwhelmed and takes time to do them
instead of having a singular function that contains everything required to roll, try splitting it up into local functions, not only improving readability but also general performance
i am sorry for responding back late but what you said actualy kinda helped
the time between the outputs is 0.3 seconds which is way better than the 1.5 seconds in the screenshot above
ty!