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?
You can use RenderStepped that fires everytime a frame is rendered in place of the while true do loop. Example:
local function UpdateSpeed() if plr then local Speed = math.floor(Seat.Velocity.Magnitude) Gui.Frame.SpeedLabel.Text = (Speed).."/"..(maxSpeed) else break -- Commas are ignored by the Lua interpreter so it's not necessary to put one here end end game:GetService("RunService").RenderStepped:Connect(UpdateSpeed)
Hope this helps.