As far as I am concerned, VehicleSeat.Speed (property) is not existant.
You could track the speed manually in studs per second by use of mangitude, and set aclimit that way.
I'd advise you to not use game.Workspace.Car when assigning your target - it will require you to rename all the defined areas if you change name of the car, and can even cause issues / conflicts if you have several vehicles named Car in your game (or if the player 'Car' joins). If the script is already parented to the car (in the front), you should navigate through the hierarchy from there.
Since I have no idea how your hierarchy works for the car, I'll just assign a variable to it for now. Feel free to change it to your liking.
local vehicle = game.Workspace.Car
local speed = 0
local speedForCrash = 20
local refreshRate = 0.5
local lastPos = vehicle.VehicleSeat.Position
script.Parent.Touched:connect(function(hit)
if (hit and (vehicle.VehicleSpeed.Throttle == 1) and (speed > speedForCrash)) then
vehicle:BreakJoints()
end
end)
while true do
local magn = (vehicle.VehicleSeat.Position - lastPos).magnitude
speed = magn/refreshRate
print(speed)
lastPos = vehicle.VehicleSeat.Position
wait(refreshRate)
end
4 comments
You can just do seat.Velocity.magnitude. (assuming 'seat' is the VehicleSeat) It's a Vector3, too. It's a quicker method and easier to read.
Raven, this is the old way of doing it, until it was discovered Velocity.magnitude can be done to get speeds.
Oh! Then I learned something new today, too! Awesome. Thanks for letting me know.
I know, you are a user from, well, I remember your name all over the place way back when. So I figured you still did things old-fashoned. So, it's good to learn the modern methods. :P