Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
2
Answered by 4 years ago

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

0
It is much cleaner in this format. You should accept this answer. EH2019SIT 78 — 4y
Ad

Answer this question