Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can can I get a Speedometer to update when I accelerate?

Sorry if the title was kinda confusing, I didn't know how to put it any other way.

I'm trying to make a speedometer for a car and I can get the speed to be printed out as fast as I want, but when I try to change the GUI's text it stays at 0.

I have a NumberValue in my VehicleSeat along with my script, thats what I'm referring to as Speedometer.

I was wondering how I can make the GUI update in a way, like when I press W it doesn't stay at 0 it accelerates up to however fast you go.

Hope you can help, heres my code.


local sp = script.Parent
local speedometer = script.Parent.Speedometer.Value

while wait() do local speed = math.floor(sp.Velocity.Magnitude + 0.5)
	
	speedometer = speed
	print(speedometer)
	game.StarterGui.ScreenGui.TextLabel.Text = speedometer
	wait(0.1)
	
end

1 answer

#Why it won't work

When you join the ScreenGui changes its parent to the PlayerGui, fx. like the StarterCharacterScripts contents comes in the character of course.

#How to fix

This is in a local script, parent the localscript to the screenGui. -- IMPORTANT

local sp = -- where it is located
local speedometer = -- where the speedometer is located
	 
while wait() do local speed = math.floor(sp.Velocity.Magnitude + 0.5)
	 
    speedometer = speed
     print(speedometer)
    script.Parent.TextLabel.Text = speedometer
    wait(0.1)	 
end

1 comment

0

It is much cleaner in this format. You should accept this answer.

This discussion is preserved as it was. New answers, comments, and votes are closed.