My goal: Being able to read the current speed of my vehicle, in order to limit the driver to a max speed, if it has been reached.
My issue: My script considers that the speed (assemblylinearvelocity.Magnitude) is always 0 and is not changing, even though my car is clearly in motion.
local moverSeat = script.Parent.moverSeat
local vectorForce = script.Parent.Base.VectorForce
local force = 300
local forceVector = script.Parent.Base.CFrame.RightVector
local MAXSPEED = 20
moverSeat:GetPropertyChangedSignal("Throttle"):Connect(function()
if moverSeat.Throttle == 1 then
vectorForce.Force = forceVector * force
elseif moverSeat.Throttle == -1 then
vectorForce.Force = -forceVector * force
elseif moverSeat.Throttle == 0 then
vectorForce.Force = Vector3.new(0,0,0)
end
end)
script.Parent.Base:GetPropertyChangedSignal("AssemblyLinearVelocity"):Connect(function()
local currentSpeed = script.Parent.Base.AssemblyLinearVelocity.Magnitude
print(currentSpeed) --this doesn't even output the speed
if currentSpeed >= MAXSPEED then
vectorForce.Force = Vector3.new(0,0,0)
end
end)
while true do
print(speed)
wait(1)
end
This always outputs “0”
Strangely enough, testing out the vehicle ingame, i wrote
print(game.Workspace.car.Base.AssemblyLinearVelocity.Magnitude)
into the command bar. I always got the speed value from this. But not from my script.
Because I receieved the value from the manual command but not from the script, I don’t believe that the root of the problem lies in how I built the car model.
It also makes me wonder how after a lot of searching I haven’t encountered someone else have this problem.