Hey guys i currently trying to make a SpeedLimiter but i stuck to limit the TopSpeed
This is my current code:
local CurrentUnitScaling = (10/12) * 1.09728
local player = game:GetService(“Players”).LocalPlayer
local pGui = player.PlayerGui
local Agui= pGui:WaitForChild(“A-Chassis Interface”)
local TopSpeed = 100
while true do
wait()
local VelocityValue = Agui.Values.Velocity.Value
local CurrentSpeed = math.floor(CurrentUnitScaling * VelocityValue.Magnitude)
if CurrentSpeed > TopSpeed then
VelocityValue.Magnitude = TopSpeed
end
end
Error code is: Magnitude cannot be asigned to.
Any other methode or is it even possible to limit it ?
Is this one right now?
Because the VelocityValue still goes higher and the Car don’t limit the speed.
while true do
wait()
local VelocityValue = Agui.Values.Velocity.Value
local CurrentSpeed = math.floor(CurrentUnitScaling * VelocityValue.Magnitude)
if CurrentSpeed > TopSpeed then
VelocityValue = VelocityValue.Unit * math.min(VelocityValue.Magnitude, TopSpeed)
end
end
So the Car has Velocity value from this Value the SpeedGauge gets the Current car speed and etc.
Ive tried this now to the with DriveSeat Position, DriveSeat Velocity, DriveSeat Velocity.Magnitude and the VelocityValue from the Car, all don’t work / all ignore it be like.
local VelocityValue = Agui.Values.Velocity.Value -- you're calling .Value, therefore it actually does not update the Velocity when you re-assign the variable.
local CurrentSpeed = math.floor(CurrentUnitScaling * VelocityValue.Magnitude)
if CurrentSpeed > TopSpeed then
VelocityValue = VelocityValue.Unit * TopSpeed
end
Try this.
local VelocityValue = Agui.Values.Velocity
local CurrentSpeed = math.floor(CurrentUnitScaling * VelocityValue.Value.Magnitude)
if CurrentSpeed > TopSpeed then
VelocityValue.Value = VelocityValue.Value.Unit * TopSpeed
end
local vel = Vector3.new(1, 0, 0)
local acceleration = 10
game:GetService('RunService').Heartbeat:Connect(function(dt)
if vel.Magnitude > 50 then
vel = vel.Unit * 50
end
vel += Vector3.new(acceleration * dt, 0, 0)
print(
string.format('%.2f', vel.Magnitude)
)
end)