*EDIT: now I’m using a new chassis, so this topic is useless
My vehicle customization system with A Chassis has a bug in which, when you modify the slide, it applies the modification on the server to everyone, however, when you reduce the slide, instead of decreasing the suspension value, it increases more, that is, adds more value in the suspension, I tried to set the value but when I change the front wheel it changes the back wheel too, so I don’t know what else to do, if anyone can help me I’ll be happy grateful.
Here is the server script (valorT is the Rear Wheels and valorF is the Front Wheels):
oficinaRE.OnServerEvent:Connect(function(player, tipo, carro, entrada, valor)
if not entrada or not carro or not tipo or not player then return end
if tipo == "aplicar" then
if mod == "height" then
local wheels = carro.Wheels
local valorF = nil
local valorT = nil
if valor.Frente <= 9 then
valorF = tonumber(string.format("0.0%d", math.abs(valor.Frente)))
else
local numero = math.floor(valor.Frente / 10)
local decimal = math.abs(valor.Frente % 10)
valorF = tonumber(string.format("0.%d%d", numero, decimal))
end
if valor.Tras <= 9 then
valorT = tonumber(string.format("0.0%d", math.abs(valor.Tras)))
else
local numero = math.floor(valor.Tras / 10)
local decimal = math.abs(valor.Tras % 10)
valorT = tonumber(string.format("0.%d%d", numero, decimal))
end
if valorF then
wheels.FL.Spring.MaxLength += valorF
wheels.FR.Spring.MaxLength += valorF
wheels.FL.Spring.FreeLength += valorF
wheels.FR.Spring.FreeLength += valorF
end
if valorT then
wheels.RL.Spring.MaxLength += valorT
wheels.RR.Spring.MaxLength += valorT
wheels.RL.Spring.FreeLength += valorT
wheels.RR.Spring.FreeLength += valorT
end
end
end
end
end
Client Script:
local function adicionarModificacao(mod, valor, custo)
for i, item in ipairs(lista) do
if item.Modify == mod then
lista[i] = { Modify = mod, Valor = valor, Custo = custo }
atualizarLista()
oficinaRE:FireServer("aplicar", carro, mod, valor)
print(lista)
return
end
end
table.insert(lista, { Modify = mod, Valor = valor, Custo = custo })
atualizarLista()
oficinaRE:FireServer("aplicar", carro, mod, valor)
print(lista)
end
local function ctrlDeslize(frame, cursor, min, max, lado)
local dragging = false
local startPos = nil
local frameSize = frame.AbsoluteSize
local framePos = frame.AbsolutePosition
cursor.Position = UDim2.new(0.482, 0, cursor.Position.Y.Scale, cursor.Position.Y.Offset)
frame.Number.Text = 0
cursor.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
dragging = true
startPos = input.Position.X
end
end)
cursor.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
dragging = false
if ModAtual == "rotation" then
if lado == "esquerdo" then
rotE = tonumber(frame.Number.Text)
adicionarModificacao(ModAtual, {Esquerdo = tonumber(frame.Number.Text) or 0, Direito = rotD or 0}, 800)
elseif lado == "direito" then
rotD = tonumber(frame.Number.Text)
adicionarModificacao(ModAtual, {Esquerdo = rotE or 0, Direito = tonumber(frame.Number.Text) or 0}, 800)
end
elseif ModAtual == "height" then
if lado == "frente" then
susF = tonumber(frame.Number.Text)
adicionarModificacao(ModAtual, {Frente = tonumber(frame.Number.Text) or 0, Tras = susT or 0}, 1200)
elseif lado == "tras" then
susT = tonumber(frame.Number.Text)
adicionarModificacao(ModAtual, {Frente = susF or 0, Tras = tonumber(frame.Number.Text) or 0}, 1200)
end
end
end
end)
UserInputService.InputChanged:Connect(function(input)
if input.UserInputType ~= Enum.UserInputType.MouseMovement or not dragging then return end
local mousePos = UserInputService:GetMouseLocation() - Vector2.new(0, game:GetService("GuiService"):GetGuiInset().Y)
local frameSizeX = frame.AbsoluteSize.X
local frameLeft = frame.AbsolutePosition.X
local frameRight = frameLeft + frameSizeX
local clampedMouseX = math.clamp(mousePos.X, frameLeft, frameRight)
local normalizedX = (clampedMouseX - frameLeft) / frameSizeX
cursor.Position = UDim2.new(normalizedX, 0, cursor.Position.Y.Scale, cursor.Position.Y.Offset)
local scaledValue = (normalizedX - 0.5) * 2
frame.Number.Text = math.floor(math.clamp(scaledValue * max, min, max))
end)
end
local function buttonsHandler()
local Frames = Options.Frames
local System = Options.Systems
local Title = Options.Title
-- Suspension frame + buttons
for _, a in pairs(Frames.Suspensao:GetChildren()) do
if a:IsA("TextButton") or a:IsA("ImageButton") then
if a.Name == "Height" then
a.MouseButton1Click:Connect(function()
System.Bars.Slider1.Title.Text = "Frente"
System.Bars.Slider2.Title.Text = "Trás"
System.Bars.Slider1.Bar.Number.Text = "0"
System.Bars.Slider2.Bar.Number.Text = "0"
System.Bars.Slider1.Bar.Cursor.Position = UDim2.new(0.482, 0, -1.333, 0)
System.Bars.Slider2.Bar.Cursor.Position = UDim2.new(0.482, 0, -1.333, 0)
criarAnim(Frames.Suspensao, System.Bars, 0.2)
ctrlDeslize(System.Bars.Slider1.Bar, System.Bars.Slider1.Bar.Cursor, -10, 10, "frente")
ctrlDeslize(System.Bars.Slider2.Bar, System.Bars.Slider2.Bar.Cursor, -10, 10, "tras")
ModAtual = "height"
end)
elseif a.Name == "Rotation" then
a.MouseButton1Click:Connect(function()
System.Bars.Slider1.Title.Text = "Esquerda"
System.Bars.Slider2.Title.Text = "Direita"
System.Bars.Slider1.Bar.Number.Text = "0"
System.Bars.Slider2.Bar.Number.Text = "0"
System.Bars.Slider1.Bar.Cursor.Position = UDim2.new(0.482, 0, -1.333, 0)
System.Bars.Slider2.Bar.Cursor.Position = UDim2.new(0.482, 0, -1.333, 0)
criarAnim(Frames.Suspensao, System.Bars, 0.2)
ctrlDeslize(System.Bars.Slider1.Bar, System.Bars.Slider1.Bar.Cursor, -10, 10, "esquerdo")
ctrlDeslize(System.Bars.Slider2.Bar, System.Bars.Slider2.Bar.Cursor, -10, 10, "direito")
ModAtual = "rotation"
end)
end
end
end