function UpdateSpeed()
while true do
wait(0.1)
if plr then
local Speed = math.floor(Seat.Velocity.Magnitude)
Gui.Frame.SpeedLabel.Text = (Speed).."/"..(maxSpeed)
else
break;
end
end
end
Having while loops to update the speed meter works, but seems to increase lag, when I remove the function the vehicle seems to move faster. Is there any alternatives to while loops that I could use to update the text of a speed meter based on the current speed of a part?

11 comments
.Changed
.Changedisn't fired on Velocity, or positionNeither is
GetPropertyChangedSignal("Velocity")You could try checking the speed every
.5seconds which would help boost preformanceYou could also set a variable for
math.flooroutside of theUpdateSpeedfunction so you don't need to spend more time indexing.Also concatenation is slow, you can try use
:formatwith a%d%dpattern.SpeedLabel.Text = ("%d/%d"):format(Speed, maxSpeed)Also set a variable outside the
UpdateSpeedfunction forSpeedLabelso you can index it fasterWhy not use
plras the condition for the while loop, instead of using an if?while plr dogood thinking @thee
If the speed hasn't changed by more than 0.1 for more than 2 seconds or something, decrease the frequency of polling. You get the resolution of high polling, without wasting cycles doing nothing if it's not moving, or has been moving at a constant speed for a while.
Alternatively, you could bind a function :GetPropertyChangedSignal("Throttle"), and only run the loop until the throttle goes back to 0.