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

How do I measure the speed of a VehicleSeat using a variable?

So roblox has this thing, that shows you a headsupdisplay, whenever you drive that seat. Its basically just a speedometer.

local VehicleSeat = script.Parent
VehicleSeat.HeadsUpDisplay = true

I need to get the speed of the seat somehow, and use it in a variable. I was just wondering , If I can somehow use the data for the HeadsUpDisplay, for like a variable.

TLDR: I want to measure the speed of a VehicleSeat using a Variable

1 answer

✓ Accepted answer

Please mark this as solved.

I had a quick look at the Jeeps roblox has for one of it's studio templates that uses the headsupdisplay

I originally thought that there was a maybe a read only variable already part of it but apparently not.

You can though use something like this:

local Speed = script.Parent.DriveSeat.Velocity.Magnitude

The downside is that it returns a float (a decimal) So you'll end up with extremely long numbers like 79.9746372845. I recommend you use some rounding to fix that though.

Edit:

I did just double check this and made a little line of code for printing it. Since you can't print a float or an integer remember to convert to string first with tostring() print(tostring(Speed))

Edit2:

If it is returning 0 here is what I suggest: Create a new script inside the drive seat with the following code:

while true do
    wait(1)
    print(tostring(script.Parent.Velocity.Magnitude))
end

And make sure your driving the vehicle! Else your number will stay at 0 because your not moving!

8 comments

0

When I try to print it, all I get is 0

0

If your trying to print it convert it to a string first.

0

Are you printing it before the vehicle starts moving?

0

Its still at 0. I added a wait(5) before printing, so i would have time to drive before It prints. I also have no idea how to convert it to a string.

0

See edit2

0

Thanks, it worked! Now how can I use this number in a variable? Can I do local speed = script.Parent.Velocity.Magnitude ?

0

Yes that's exactly how you would use it.

0

Ok, thank you so much!

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