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

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

Asked by 3 years ago

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

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

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!

0
When I try to print it, all I get is 0 mcslimeman 37 — 3y
0
If your trying to print it convert it to a string first. PURGATORYAGENT_1 43 — 3y
0
Are you printing it before the vehicle starts moving? Amiaa16 3227 — 3y
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. mcslimeman 37 — 3y
View all comments (4 more)
0
See edit2 PURGATORYAGENT_1 43 — 3y
0
Thanks, it worked! Now how can I use this number in a variable? Can I do local speed = script.Parent.Velocity.Magnitude ? mcslimeman 37 — 3y
0
Yes that's exactly how you would use it. PURGATORYAGENT_1 43 — 3y
0
Ok, thank you so much! mcslimeman 37 — 3y
Ad

Answer this question