i'm trying to make a physical text speedometer for my car, and i'm using string.sub to only show the main values of the speed in km/h, and i'm making it update if the main numbers are 1 digit, 2 digits or 3 digits, by using three separate string.sub's, but it doesn't properly work, because sometimes it doesnt switch properly, as the values change incorrectly, can i have any help with getting this to correctly work? any help is greatly appreciated!
this is the code
script.Parent.Values.Velocity.Changed:connect(function()
wait()
--local sps = script.Parent.Values.Velocity.Value.Magnitude (held as comment to save later)
local sps = car.DriveSeat.Velocity.Magnitude
local ips = sps * 10 --inches per second
local mph = ips * 0.568182 -- miles per hour
local kmh = mph * 1.60934 --kilometers per hour
local stringnumber = tostring(kmh)
local speed = string.sub(stringnumber, 0, 1)
local speed2 = string.sub(stringnumber, 0, 2)
local speed3 = string.sub(stringnumber, 0, 3)
local spddis = car.Body.Speed.Gui
script.kmh.Value = kmh/10
spddis.One.Text = speed
if kmh <= 1 then
spddis.Zero.Visible = true
end
if kmh <= 9 and kmh >= 1 then
spddis.Zero.Visible = false
spddis.One.Text = speed
end
if kmh <= 99 and kmh >= 10 then
spddis.Zero.Visible = false
spddis.One.Text = speed2
end
if kmh <= 1000 and kmh >= 99 then
spddis.Zero.Visible = false
spddis.One.Text = speed3
end
end)

1 comment
8mo later, i should've told you to floor it :v