Hello Developers,
i have a problem with my RPM gauge, for some reason between 45-60kmh, the rpm gauge goes to a negative value, I have no idea why, there is a math clamp next to it preventing it from going to negative value.
here is the script
local connection = script.Parent.Value.Value
local config = require(connection:WaitForChild("config"))
local rpmgauge = connection.Misc["rpm gauge"]
local speedgauge = connection.Misc["Speed gauge"]
local currentspeed = connection.GUI.Values.currentspeed
local rpmvalue = connection.GUI.Values.rpm
local speedgaugehinge = speedgauge.Hinge.HingeConstraint
local rpmgaugehinge = rpmgauge.Hinge.HingeConstraint
local UIS = game:GetService("UserInputService")
local function Round(x, mult)
return math.round(x / mult) * mult
end
game["Run Service"].Heartbeat:Connect(function()
local min = (config.MinRPM / -12.5)
local peak = (config.RPMpeak / -12.5)
local boost = (config.RPMboost / -12.5)
local max = (config.MaxRPM / -12.5)
if connection.GUI.Values.IsDriving.Value == false then
rpmgaugehinge.TargetAngle = 0
end
if rpmgaugehinge.TargetAngle > 0 then
rpmgaugehinge.TargetAngle = 0
end
if rpmgaugehinge.TargetAngle < -270 then
rpmgaugehinge.TargetAngle = -270
end
if connection.GUI.Values.rpm.Value < 0 then
connection.GUI.Values.rpm.Value = math.clamp(connection.GUI.Values.rpm.Value, 0, config.MaxRPM)
end
script.Parent.cargui.rpm.Text = "RPM:"..Round(rpmgaugehinge.CurrentAngle * -12.5, 1)
if connection.VehicleSeat.ThrottleFloat == 1 and UIS:IsKeyDown(Enum.KeyCode.LeftShift) then
if currentspeed.Value < -1 then
rpmgaugehinge.TargetAngle = Round(math.clamp((config.RPMboost + (currentspeed.Value * config.Rratio) * config.Rratio) / -12.5, max, min), 0.1)
elseif currentspeed.Value > 1 and currentspeed.Value < config.D1 then
rpmgaugehinge.TargetAngle = Round(math.clamp((config.RPMboost + (currentspeed.Value * config.D1ratio) * config.D1ratio) / -12.5, max, min), 0.1)
elseif currentspeed.Value > config.D1 and currentspeed.Value < config.D2 then
rpmgaugehinge.TargetAngle = Round(math.clamp((config.RPMboost + (currentspeed.Value * config.D2ratio) * config.D2ratio) / -12.5, max, min), 0.1)
elseif currentspeed.Value > config.D2 and currentspeed.Value < config.D3 then
rpmgaugehinge.TargetAngle = Round(math.clamp((config.RPMboost + (currentspeed.Value * config.D3ratio) * config.D3ratio) / -12.5, max, min), 0.1)
elseif currentspeed.Value > config.D3 and currentspeed.Value < config.D4 then
rpmgaugehinge.TargetAngle = Round(math.clamp((config.RPMboost + (currentspeed.Value * config.D4ratio) * config.D4ratio) / -12.5, max, min), 0.1)
elseif currentspeed.Value > config.D4 and currentspeed.Value < config.D5 then
rpmgaugehinge.TargetAngle = Round(math.clamp((config.RPMboost + (currentspeed.Value * config.D5ratio) * config.D5ratio) / -12.5, max, min), 0.1)
end
end
rpmvalue.Value = rpmgaugehinge.CurrentAngle * -12.5
speedgaugehinge.TargetAngle = math.clamp(currentspeed.Value * -1.6875, -270, 0) -- MAX SPEEDOMETER 160
end)
and here is the config script:
config.MinRPM = 600
config.RPMpeak = 1200
config.RPMboost = 1600
config.MaxRPM = 3500
-- Gears speeds (max km/h)
config.R = 10
config.D1 = 20
config.D2 = 35
config.D3 = 50
config.D4 = 80
config.D5 = 110 -- put above so rpm doesnt go negative
config.Rratio = 6
config.D1ratio = 5
config.D2ratio = 4
config.D3ratio = 3.8
config.D4ratio = 2.5
config.D5ratio = 2.1

