i am currently trying to make an rpm bar on a dashboard, and I want the bar to scale with the rpm. the method i have right now is really messy and takes up unnecessary code, plus it is very tedious. is there a better way to do this?
function rpmChange()
if carstatus.Value then
local rpmBar = sc.G.RPMGauge.RPM
sc.G.RPMV.Text = tostring(math.floor(rpm.Value))
if math.floor(rpm.Value) >= 500 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 1000 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 1500 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 2000 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 2500 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 3000 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 3500 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 4000 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 4250 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 4500 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 4750 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 5000 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 5250 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 5500 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 5750 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" or v.Name == "R15" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 6000 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" or v.Name == "R15" or v.Name == "R16" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 6250 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" or v.Name == "R15" or v.Name == "R16" or v.Name == "R17" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 6500 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" or v.Name == "R15" or v.Name == "R16" or v.Name == "R17" or v.Name == "R18" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 6750 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" or v.Name == "R15" or v.Name == "R16" or v.Name == "R17" or v.Name == "R18" or v.Name == "R19" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 7000 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" or v.Name == "R15" or v.Name == "R16" or v.Name == "R17" or v.Name == "R18" or v.Name == "R19" or v.Name == "R20" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 7250 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" or v.Name == "R15" or v.Name == "R16" or v.Name == "R17" or v.Name == "R18" or v.Name == "R19" or v.Name == "R20" or v.Name == "R21" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 7500 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" or v.Name == "R15" or v.Name == "R16" or v.Name == "R17" or v.Name == "R18" or v.Name == "R19" or v.Name == "R20" or v.Name == "R21" or v.Name == "R22" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 7750 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" or v.Name == "R15" or v.Name == "R16" or v.Name == "R17" or v.Name == "R18" or v.Name == "R19" or v.Name == "R20" or v.Name == "R21" or v.Name == "R22" or v.Name == "R23" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 8000 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" or v.Name == "R15" or v.Name == "R16" or v.Name == "R17" or v.Name == "R18" or v.Name == "R19" or v.Name == "R20" or v.Name == "R21" or v.Name == "R22" or v.Name == "R23" or v.Name == "R24" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 8250 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" or v.Name == "R15" or v.Name == "R16" or v.Name == "R17" or v.Name == "R18" or v.Name == "R19" or v.Name == "R20" or v.Name == "R21" or v.Name == "R22" or v.Name == "R23" or v.Name == "R24" or v.Name == "R25" then
v.Visible = true
else
v.Visible = false
end
end
elseif math.floor(rpm.Value) >= 8500 then
for i, v in pairs(rpmBar:GetChildren()) do
if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" or v.Name == "R15" or v.Name == "R16" or v.Name == "R17" or v.Name == "R18" or v.Name == "R19" or v.Name == "R20" or v.Name == "R21" or v.Name == "R22" or v.Name == "R23" or v.Name == "R24" or v.Name == "R25" or v.Name == "R26" then
v.Visible = true
else
v.Visible = false
end
end
end
end
end