Wait(inf) becomes wait()

I am making a speedometer and when wait becomes inf (1/0) it counts as wait()
Is there any way to make the wait time just inf?

local UNITS = {								--Click on speed to change units
	--First unit is default	
	{
		units			= "km/h"			,
		scaling			= (10/12) * 1.09728	, -- 1 stud : 10 inches | ft/s to KP/H
		maxSpeed		= 120				,
		spInc			= 20				, -- Increment between labelled notches
	}
}
local currentUnits = 1
local values = script.Parent.Parent.Parent.Values
while true do
	wait(1/math.floor(UNITS[currentUnits].scaling*values.Velocity.Value.Magnitude))
	script.Value.Value += 1
end

2 Likes

Making it wait(inf) in the way youre asking will make it so the loop will never run again and the code will yield forever

3 Likes

put (after the wait) a task.wait until your waitnumber is bigger than 0

Is this how am I supposed to do it?

local UNITS = {								--Click on speed to change units
	--First unit is default	
	{
		units			= "km/h"			,
		scaling			= (10/12) * 1.09728	, -- 1 stud : 10 inches | ft/s to KP/H
		maxSpeed		= 120				,
		spInc			= 20				, -- Increment between labelled notches
	}
}
local currentUnits = 1
local values = script.Parent.Parent.Parent.Values
while true do
	wait(1/math.floor(UNITS[currentUnits].scaling*values.Velocity.Value.Magnitude))
	task.wait()
	repeat until math.floor(UNITS[currentUnits].scaling*values.Velocity.Value.Magnitude) >= 0
	script.Value.Value += 1
end

1 Like

oh i thought 1/0 returns 0, here this would work

local currentUnits = 1
local values = script.Parent.Parent.Parent.Values
while true do
	wait(1/math.floor(UNITS[currentUnits].scaling*values.Velocity.Value.Magnitude))
	repeat task.wait() until 1/math.floor(UNITS[currentUnits].scaling*values.Velocity.Value.Magnitude) ~= math.huge
	script.Value.Value += 1
end
1 Like

Snímka obrazovky 2023-07-30 165247

1 Like

i have edited the script, try again

--Calculated by approximation(2^127*1.9999999) and then fine-tuned to the exact max
--Extra .999999...9 can be added, it's an approximation of ...664
local safeINF = 340282356779733642748073463979561713663
local t = math.huge
local chosen = math.min(t, safeINF)

task.wait(t)
print("1. Run")
task.wait(safeINF*1.000000000000001)
print("2. Run")
task.wait(chosen)
print("3. Doesn't Run")

Decided to leave it here for the lost souls trying to figure out the max value.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.