Hi guys,
I believe there something wrong with my equation formula
rpmgaugehinge.TargetAngle =- math.clamp(config.MinRPM + ((config.MinRPM / 5) * currentspeed.Value * config.D1ratio) / -11.15, -270, 0)
the answer to this would be -75 degrees
However, instead it goes to 500
3 Likes
J_Angry
(J_Angry)
May 10, 2024, 3:37pm
#2
I think I see the problem, you just forgot a parenthesis at the very start of your equation, which completely changed your answer from -75, to around 579. I think I fixed it here:
rpmgaugehinge.TargetAngle =- math.clamp((config.MinRPM + (config.MinRPM / 5) * currentspeed.Value * config.D1ratio) / -11.15, -270, 0)
tried this,
the rpm goes into -500 rpm if the throttle is 0
if the throttle is 1 then it goes back to 0
J_Angry
(J_Angry)
May 11, 2024, 12:34am
#4
It should work in theory. Did you change any of the variables? Like config.MinRPM
, etc.
the minimum rpm is at 600 since
J_Angry
(J_Angry)
May 11, 2024, 12:39am
#7
Wait, why does it say 500 in the screenshot? Do you change it later on in the script or something?
oops sorry, I thought it was at 600,
even if at 600 it still does weird stuff
J_Angry
(J_Angry)
May 11, 2024, 12:52am
#9
Just curious, can I see your entire code? It’ll be really helpful.
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 minrpm = config.MinRPM * 0.09
local UIS = game:GetService("UserInputService")
local tweenservice = game:GetService("TweenService")
game["Run Service"].Stepped:Connect(function()
if connection.GUI.Values.IsDriving.Value == false then
rpmgaugehinge.TargetAngle = 0
end
if connection.GUI.Values.gear.Value == "N" and connection.VehicleSeat.ThrottleFloat == 1 then
rpmgaugehinge.TargetAngle = rpmgaugehinge.TargetAngle - 5
elseif connection.GUI.Values.gear.Value == "N" and connection.VehicleSeat.ThrottleFloat == 0 then
rpmgaugehinge.TargetAngle = rpmgaugehinge.TargetAngle + 5
end
if rpmgaugehinge.TargetAngle > 0 then
rpmgaugehinge.TargetAngle = 0
end
if connection.GUI.Values.IsDriving.Value == true and rpmgaugehinge.TargetAngle < -minrpm and connection.GUI.Values.gear.Value == "N" and connection.VehicleSeat.ThrottleFloat == 0 then
rpmgaugehinge.TargetAngle = -minrpm
end
if connection.GUI.Values.IsDriving.Value == true and rpmgaugehinge.TargetAngle < -minrpm and connection.GUI.Values.gear.Value == "D1" and connection.VehicleSeat.ThrottleFloat == 0 then
rpmgaugehinge.TargetAngle = -minrpm
end
if rpmgaugehinge.TargetAngle < -270 then
rpmgaugehinge.TargetAngle = -270
end
script.Parent.cargui.rpm.Text = "RPM:"..rpmvalue.Value
if currentspeed.Value < -1 then
rpmgaugehinge.TargetAngle =- math.clamp((config.MinRPM + ((config.MinRPM / 5) * currentspeed.Value * config.Rratio) / -11.15), -270, 1110)
elseif currentspeed.Value > 1 and currentspeed.Value < config.D1 then
rpmgaugehinge.TargetAngle =- math.clamp((config.MinRPM + ((config.MinRPM / 5) * currentspeed.Value * config.D1ratio) / -11.15), -270, 1110)
elseif currentspeed.Value > config.D1 and currentspeed.Value < config.D2 then
rpmgaugehinge.TargetAngle =- math.clamp((config.MinRPM + ((config.MinRPM / 5) * currentspeed.Value * config.D2ratio) / -11.15), -270, 1110)
elseif currentspeed.Value > config.D2 and currentspeed.Value < config.D3 then
rpmgaugehinge.TargetAngle =- math.clamp((config.MinRPM + ((config.MinRPM / 5) * currentspeed.Value * config.D3ratio) / -11.15), -270, 1110)
elseif currentspeed.Value > config.D3 and currentspeed.Value < config.D4 then
rpmgaugehinge.TargetAngle =- math.clamp((config.MinRPM + ((config.MinRPM / 5) * currentspeed.Value * config.D4ratio) / -11.15), -270, 1110)
elseif currentspeed.Value > config.D4 and currentspeed.Value < config.D5 then
rpmgaugehinge.TargetAngle =- math.clamp((config.MinRPM + ((config.MinRPM / 5) * currentspeed.Value * config.D5ratio) / -11.15), -270, 1110)
end
if connection.VehicleSeat.ThrottleFloat == 1 then
if currentspeed.Value < -1 then
rpmgaugehinge.TargetAngle =- math.clamp(config.RPMpeak + ((config.RPMpeak / 10) * currentspeed.Value * config.Rratio) / -11.15, -270, 1110)
elseif currentspeed.Value > 1 and currentspeed.Value < config.D1 then
rpmgaugehinge.TargetAngle =- math.clamp(config.RPMpeak + ((config.RPMpeak / 10) * currentspeed.Value * config.D1ratio) / -11.15, -270, 1110)
elseif currentspeed.Value > config.D1 and currentspeed.Value < config.D2 then
rpmgaugehinge.TargetAngle =- math.clamp(config.RPMpeak + ((config.RPMpeak / 10) * currentspeed.Value * config.D2ratio) / -11.15, -270, 1110)
elseif currentspeed.Value > config.D2 and currentspeed.Value < config.D3 then
rpmgaugehinge.TargetAngle =- math.clamp(config.RPMpeak + ((config.RPMpeak / 10) * currentspeed.Value * config.D3ratio) / -11.15, -270, 1110)
elseif currentspeed.Value > config.D3 and currentspeed.Value < config.D4 then
rpmgaugehinge.TargetAngle =- math.clamp(config.RPMpeak + ((config.RPMpeak / 10) * currentspeed.Value * config.D4ratio) / -11.15, -270, 1110)
elseif currentspeed.Value > config.D4 and currentspeed.Value < config.D5 then
rpmgaugehinge.TargetAngle =- math.clamp(config.RPMpeak + ((config.RPMpeak / 10) * currentspeed.Value * config.D5ratio) / -11.15, -270, 1110)
end
end
if connection.VehicleSeat.ThrottleFloat == 1 and UIS:IsKeyDown(Enum.KeyCode.LeftShift) then
if currentspeed.Value < -1 then
rpmgaugehinge.TargetAngle =- math.clamp(config.RPMboost + ((config.RPMboost / 10) * currentspeed.Value * config.Rratio) / -11.15, -270, 1110)
elseif currentspeed.Value > 1 and currentspeed.Value < config.D1 then
rpmgaugehinge.TargetAngle =- math.clamp(config.RPMboost + ((config.RPMboost / 10) * currentspeed.Value * config.D1ratio) / -11.15, -270, 1110)
elseif currentspeed.Value > config.D1 and currentspeed.Value < config.D2 then
rpmgaugehinge.TargetAngle =- math.clamp(config.RPMboost + ((config.RPMboost / 10) * currentspeed.Value * config.D2ratio) / -11.15, -270, 1110)
elseif currentspeed.Value > config.D2 and currentspeed.Value < config.D3 then
rpmgaugehinge.TargetAngle =- math.clamp(config.RPMboost + ((config.RPMboost / 10) * currentspeed.Value * config.D3ratio) / -11.15, -270, 1110)
elseif currentspeed.Value > config.D3 and currentspeed.Value < config.D4 then
rpmgaugehinge.TargetAngle =- math.clamp(config.RPMboost + ((config.RPMboost / 10) * currentspeed.Value * config.D4ratio) / -11.15, -270, 1110)
elseif currentspeed.Value > config.D4 and currentspeed.Value < config.D5 then
rpmgaugehinge.TargetAngle =- math.clamp(config.RPMboost + ((config.RPMboost / 10) * currentspeed.Value * config.D5ratio) / -11.15, -270, 1110)
end
end
rpmvalue.Value = rpmgaugehinge.CurrentAngle * 11.15
rpmgaugehinge.TargetAngle = rpmgaugehinge.TargetAngle * -1
--rpmgaugehinge.TargetAngle = math.clamp(-rpmvalue.Value/ 11.15, -270, 0)
speedgaugehinge.TargetAngle = math.clamp(currentspeed.Value * -1.6875, -270, 0) -- MAX SPEEDOMETER 160
end)
J_Angry
(J_Angry)
May 11, 2024, 12:57am
#11
In rpmgaugehinge.TargetAngle =- math.clamp((config.MinRPM + ((config.MinRPM / 5) * currentspeed.Value * config.D1ratio) / -11.15), -270, 1110)
, what is the 1110
for? Just wondering, as the original code you had say it was 0
.
i changed it to see if the number would go positive or negative range
J_Angry
(J_Angry)
May 11, 2024, 1:18am
#13
If you print rpmgaugehinge.TargetAngle
, will it be limited to -270
and 1110
? Also, is this in a local script? I did some research and it said CurrentAngle
only works in a local script.
yes probably.
yes its in a local script.