A simple idea, I understand how I could do this but I’d like to know if there’s any better way to do it.
While variable > 0 do
variable -= 0.1
wait(0.1)
end
I’m worried that while this could work, that it’d be inefficient as hell due to the script having to constantly repeat these things, alongside this running alongside other functions. If this is the best way to do it, so be it, but I believe that there’s a better method right?
local RunService = game:GetService("RunService")
local runConnection = nil
local valueToChange = 1
local lastUpdate = 0
runConnection = RunService.Stepped:Connect(function(_, deltaTime: number)
if (os.clock() - lastUpdate) < 0.1 then
return
end
valueToChange = math.clamp(valueToChange - deltaTime, 0, math.huge)
lastUpdate = os.clock()
print(valueToChange)
if valueToChange <= 0 then
return runConnection:Disconnect()
end
end)
My apologies for needing to take up more of your time, but could you tell me what your script does better? Is it optimization, consistency, or something else entirely?