When i try to drive and i press W and S its driving me sideways left and right not front & back. Any fixes ya’ll?
local VehSeat = script.Parent
-- Create RemoteEvent if it doesn't exist
local RE = VehSeat:FindFirstChild("RemoteEvent") or Instance.new("RemoteEvent", VehSeat)
RE.Name = "RemoteEvent"
-- Make sure VehSeat exists before proceeding
if not VehSeat then
warn("VehicleSeat not found. Script must be parented to a VehicleSeat.")
return
end
local vehicle = VehSeat.Parent
local body = vehicle.PrimaryPart
-- Make sure body exists
if not body then
warn("Vehicle body not found. Make sure the VehicleSeat has a parent with a Body part or use the parent itself.")
return
end
-- Configuration
local SPEED = 60 -- Forward/backward speed
local TURN_SPEED = 2 -- Turning speed
-- Variables
local controls = {
forward = false,
backward = false,
left = false,
right = false
}
-- Listen for control updates from client
RE.OnServerEvent:Connect(function(player, controlsData)
-- Verify the player is actually seated in this vehicle
if VehSeat.Occupant and VehSeat.Occupant.Parent and game.Players:GetPlayerFromCharacter(VehSeat.Occupant.Parent) == player then
controls = controlsData
end
end)
-- Main driving loop
game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
if not VehSeat.Occupant or not body then return end
local moveDirection = Vector3.new(0, 0, 0)
local rotateAmount = 0
-- Calculate movement direction
if controls.forward then
moveDirection = moveDirection + (body.CFrame.LookVector * SPEED)
end
if controls.backward then
moveDirection = moveDirection - (body.CFrame.LookVector * SPEED)
end
-- Calculate rotation
if controls.left then
rotateAmount = rotateAmount + TURN_SPEED
end
if controls.right then
rotateAmount = rotateAmount - TURN_SPEED
end
-- Apply movement
if moveDirection.Magnitude > 0 then
vehicle:SetPrimaryPartCFrame(body.CFrame + moveDirection * deltaTime)
end
-- Apply rotation
if rotateAmount ~= 0 then
vehicle:SetPrimaryPartCFrame(body.CFrame * CFrame.Angles(0, math.rad(rotateAmount), 0))
end
end)