-- BMW M3 GTR (E46 / Most Wanted-inspired) | Blue + Silver | Raycast suspension | Drift physics | Nitro | HUD -- -- Controls -- W / S gas, brake, reverse (arrow keys work too) -- A / D steer -- SPACE handbrake / drift -- LEFT SHIFT nitro -- L headlights G underglow -- C camera (chase / far / cockpit) hold RIGHT MOUSE to look around -- E enter / exit R flip car upright -- T respawn car in front of you -- F1 hide / show controls -- [ remove the car and the script -- -- NOTE: the car is built locally, so only YOU see it (client-side script). local Players = game:GetService("Players") local RunService = game:GetService("RunService") local UserInputService = game:GetService("UserInputService") local CoreGui = game:GetService("CoreGui") local LocalPlayer = Players.LocalPlayer ---------------------------------------------------------------- -- Config ---------------------------------------------------------------- local CONFIG = { bodyColor = Color3.fromRGB(205, 211, 218), -- M3 GTR silver body hideDriver = true, -- the R15 rig is taller than the cabin, so hide it while driving autoEnter = true, -- sit in the car right after it spawns -- Optional sounds: paste Roblox audio asset ids like "rbxassetid://123456" (leave "" to disable) engineSoundId = "", hornSoundId = "", } ---------------------------------------------------------------- -- Tuning ---------------------------------------------------------------- local WHEEL_R = 1.3 local MOUNT_Y = -0.3 local SPRING_LEN = 2.1 local REST_DIST = 1.6 local RAY_LEN = 2.5 local MU_FRONT = 1.7 local MU_REAR = 1.55 local GRIP_GAIN = 0.9 local GEAR_MAX = {48, 85, 120, 155, 190, 228} local GEAR_ACCEL = {95, 80, 66, 54, 45, 38} local REVERSE_ACCEL = 42 local REVERSE_MAX = 48 local BRAKE_DECEL = 130 local HAND_DECEL = 55 local ROLL_DECEL = 7 local DRAG_LIN = 0.015 local DRAG_QUAD = 0.0001 local DOWNFORCE = 0.0006 local MAX_STEER_LOW = 34 -- degrees at standstill local MAX_STEER_HIGH = 8 -- degrees at high speed local KMH = 1.008 -- studs/s -> km/h (1 stud = 0.28 m) local WHEEL_DEFS = { {name = "FL", x = -3.05, z = -4.5, front = true}, {name = "FR", x = 3.05, z = -4.5, front = true}, {name = "RL", x = -3.05, z = 4.3, front = false}, {name = "RR", x = 3.05, z = 4.3, front = false}, } ---------------------------------------------------------------- -- State ---------------------------------------------------------------- local car = nil local driving = false local connections = {} local hiddenParts = {} local savedHumanoid = nil local hudVisibleHints = true local camState = {yaw = 0, pos = nil, fov = 70, orbitYaw = 0, orbitPitch = 0, mode = 1, rmb = false} local originalFov = 70 local rayParams = RaycastParams.new() rayParams.FilterType = Enum.RaycastFilterType.Exclude rayParams.IgnoreWater = true pcall(function() rayParams.RespectCanCollide = true end) ---------------------------------------------------------------- -- Helpers ---------------------------------------------------------------- local function new(class, props, parent) local inst = Instance.new(class) for key, value in pairs(props) do inst[key] = value end inst.Parent = parent return inst end local function rot(x, y, z) return CFrame.Angles(math.rad(x), math.rad(y), math.rad(z)) end local function at(x, y, z, r) if r then return CFrame.new(x, y, z) * r end return CFrame.new(x, y, z) end local function commas(n) local s = tostring(math.floor(n)) local r = s:reverse():gsub("(%d%d%d)", "%1,") r = r:reverse() if r:sub(1, 1) == "," then r = r:sub(2) end return r end local function updateRayFilter() local list = {} if car then table.insert(list, car.model) end if LocalPlayer.Character then table.insert(list, LocalPlayer.Character) end rayParams.FilterDescendantsInstances = list end local function makeSound(parent, id, looped, volume) if id == "" then return nil end return new("Sound", { SoundId = id, Looped = looped, Volume = volume, RollOffMaxDistance = 250, }, parent) end ---------------------------------------------------------------- -- HUD ---------------------------------------------------------------- local hud = {} do local gui = Instance.new("ScreenGui") gui.Name = "M3GTRHUD" gui.ResetOnSpawn = false gui.IgnoreGuiInset = true pcall(function() gui.Parent = CoreGui end) if not gui.Parent then gui.Parent = LocalPlayer:WaitForChild("PlayerGui") end hud.gui = gui local panel = new("Frame", { AnchorPoint = Vector2.new(1, 1), Position = UDim2.new(1, -28, 1, -28), Size = UDim2.new(0, 300, 0, 130), BackgroundColor3 = Color3.fromRGB(12, 12, 14), BackgroundTransparency = 0.35, BorderSizePixel = 0, Visible = false, }, gui) new("UICorner", {CornerRadius = UDim.new(0, 12)}, panel) new("UIStroke", {Color = Color3.fromRGB(25, 75, 170), Thickness = 1.5, Transparency = 0.3}, panel) hud.panel = panel hud.speed = new("TextLabel", { Position = UDim2.new(0, 14, 0, 4), Size = UDim2.new(0, 190, 0, 70), BackgroundTransparency = 1, Text = "0", TextColor3 = Color3.fromRGB(255, 255, 255), TextSize = 64, Font = Enum.Font.GothamBlack, TextXAlignment = Enum.TextXAlignment.Left, }, panel) new("TextLabel", { Position = UDim2.new(0, 16, 0, 70), Size = UDim2.new(0, 80, 0, 18), BackgroundTransparency = 1, Text = "KM/H", TextColor3 = Color3.fromRGB(180, 180, 185), TextSize = 15, Font = Enum.Font.GothamBold, TextXAlignment = Enum.TextXAlignment.Left, }, panel) hud.gear = new("TextLabel", { Position = UDim2.new(1, -96, 0, 6), Size = UDim2.new(0, 82, 0, 80), BackgroundTransparency = 1, Text = "N", TextColor3 = Color3.fromRGB(25, 75, 170), TextSize = 64, Font = Enum.Font.GothamBlack, TextXAlignment = Enum.TextXAlignment.Right, }, panel) local rpmBack = new("Frame", { Position = UDim2.new(0, 14, 1, -40), Size = UDim2.new(0, 272, 0, 10), BackgroundColor3 = Color3.fromRGB(35, 35, 40), BorderSizePixel = 0, ClipsDescendants = true, }, panel) new("UICorner", {CornerRadius = UDim.new(1, 0)}, rpmBack) hud.rpmClip = new("Frame", { Size = UDim2.new(0, 0, 1, 0), BackgroundTransparency = 1, ClipsDescendants = true, }, rpmBack) local rpmGrad = new("Frame", { Size = UDim2.new(0, 272, 1, 0), BackgroundColor3 = Color3.fromRGB(255, 255, 255), BorderSizePixel = 0, }, hud.rpmClip) new("UIGradient", { Color = ColorSequence.new({ ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 255, 255)), ColorSequenceKeypoint.new(0.6, Color3.fromRGB(255, 150, 40)), ColorSequenceKeypoint.new(0.85, Color3.fromRGB(255, 60, 20)), ColorSequenceKeypoint.new(1, Color3.fromRGB(255, 0, 0)), }), }, rpmGrad) local nitroBack = new("Frame", { Position = UDim2.new(0, 14, 1, -22), Size = UDim2.new(0, 272, 0, 6), BackgroundColor3 = Color3.fromRGB(35, 35, 40), BorderSizePixel = 0, }, panel) new("UICorner", {CornerRadius = UDim.new(1, 0)}, nitroBack) hud.nitro = new("Frame", { Size = UDim2.new(1, 0, 1, 0), BackgroundColor3 = Color3.fromRGB(70, 170, 255), BorderSizePixel = 0, }, nitroBack) new("UICorner", {CornerRadius = UDim.new(1, 0)}, hud.nitro) hud.drift = new("TextLabel", { AnchorPoint = Vector2.new(0.5, 0.5), Position = UDim2.new(0.5, 0, 0.14, 0), Size = UDim2.new(0, 520, 0, 50), BackgroundTransparency = 1, Text = "", TextColor3 = Color3.fromRGB(255, 140, 40), TextSize = 40, Font = Enum.Font.GothamBlack, }, gui) new("UIStroke", {Thickness = 2, Color = Color3.fromRGB(0, 0, 0), Transparency = 0.4}, hud.drift) hud.driftSub = new("TextLabel", { AnchorPoint = Vector2.new(0.5, 0.5), Position = UDim2.new(0.5, 0, 0.14, 40), Size = UDim2.new(0, 520, 0, 30), BackgroundTransparency = 1, Text = "", TextColor3 = Color3.fromRGB(255, 255, 255), TextSize = 24, Font = Enum.Font.GothamBold, }, gui) new("UIStroke", {Thickness = 1.5, Color = Color3.fromRGB(0, 0, 0), Transparency = 0.4}, hud.driftSub) hud.hints = new("TextLabel", { AnchorPoint = Vector2.new(0, 1), Position = UDim2.new(0, 16, 1, -16), Size = UDim2.new(0, 420, 0, 110), BackgroundTransparency = 1, Text = "W/S gas, brake, reverse A/D steer\nSPACE drift SHIFT nitro\nL lights G underglow C camera\nE enter/exit R flip T respawn\nF1 hide this [ remove", TextColor3 = Color3.fromRGB(255, 255, 255), TextTransparency = 0.25, TextSize = 15, Font = Enum.Font.GothamMedium, TextXAlignment = Enum.TextXAlignment.Left, TextYAlignment = Enum.TextYAlignment.Bottom, Visible = false, }, gui) new("UIStroke", {Thickness = 1, Color = Color3.fromRGB(0, 0, 0), Transparency = 0.5}, hud.hints) hud.flash = 0 end ---------------------------------------------------------------- -- Car builder ---------------------------------------------------------------- local function buildCar(spawnCF) local model = Instance.new("Model") model.Name = "BMW_M3_GTR_E46" model.Parent = workspace local chassis = Instance.new("Part") chassis.Name = "Chassis" chassis.Size = Vector3.new(6.2, 1.4, 13.8) chassis.Transparency = 1 chassis.Anchored = true chassis.CanCollide = true chassis.TopSurface = Enum.SurfaceType.Smooth chassis.BottomSurface = Enum.SurfaceType.Smooth chassis.CustomPhysicalProperties = PhysicalProperties.new(3, 0.05, 0, 100, 100) chassis.CFrame = spawnCF chassis.Parent = model model.PrimaryPart = chassis local V = Vector3.new local ORANGE = CONFIG.bodyColor -- silver body panels local BLUE = Color3.fromRGB(18, 55, 145) local RACING_BLUE = Color3.fromRGB(28, 82, 190) local SILVER = Color3.fromRGB(218, 224, 230) local BLACK = Color3.fromRGB(18, 18, 20) local DARK = Color3.fromRGB(38, 38, 42) local GLASS = Color3.fromRGB(70, 95, 110) local CHROME = Color3.fromRGB(215, 215, 220) local DIM_WHITE = Color3.fromRGB(190, 190, 185) local DIM_RED = Color3.fromRGB(110, 15, 15) local CYL = Enum.PartType.Cylinder local function add(name, size, offset, color, material, props, weldTo) local p = Instance.new("Part") p.Name = name p.Size = size p.Color = color p.Material = material or Enum.Material.SmoothPlastic p.TopSurface = Enum.SurfaceType.Smooth p.BottomSurface = Enum.SurfaceType.Smooth p.CanCollide = false p.CanQuery = false p.CanTouch = false p.Massless = true p.Anchored = false if color == ORANGE then p.Reflectance = 0.1 end if props then for key, value in pairs(props) do p[key] = value end end p.CFrame = chassis.CFrame * offset p.Parent = model local weld = Instance.new("WeldConstraint") weld.Part0 = p weld.Part1 = weldTo or chassis weld.Parent = p return p end local car = { model = model, chassis = chassis, wheels = {}, headLenses = {}, headLights = {}, tailLamps = {}, tailLights = {}, reverseLamps = {}, underglow = {}, underglowLight = nil, flames = {}, steerInput = 0, steerAngle = 0, rearGrip = 1, nitro = 100, boosting = false, gear = 1, shiftTimer = 0, rpm = 0.1, lightsOn = false, glowOn = false, popRequest = false, prevDrive = 0, speed = 0, fSpeed = 0, slipDeg = 0, drifting = false, brakeAmount = 0, throttle = 0, reversing = false, lightState = {head = nil, brake = nil, rev = nil, glow = nil}, drift = {active = false, time = 0, score = 0, combo = 1, endTimer = 0}, totalScore = 0, } ---------------- Body ---------------- add("Tub", V(5.6, 1.5, 14), at(0, 0.1, 0), ORANGE) add("FrontBumper", V(6.2, 1.2, 1.1), at(0, 0.1, -7.45), ORANGE) add("RearBumper", V(6.2, 1.3, 1.0), at(0, 0.05, 7.45), ORANGE) add("Splitter", V(6.4, 0.14, 1.4), at(0, -0.62, -7.7), BLACK) add("Diffuser", V(5.2, 0.25, 1.6), at(0, -0.62, 7.4), BLACK) -- E46 M3 GTR widebody: broad front/rear arches and low race bumpers add("FrontLowerLip", V(6.55, 0.18, 1.0), at(0, -0.48, -7.9), BLACK) add("RearLowerValance", V(5.9, 0.28, 0.55), at(0, -0.42, 7.88), BLACK) add("FrontCanardL", V(0.9, 0.12, 0.65), at(-3.0, -0.28, -7.65, rot(0, -12, -8)), BLUE) add("FrontCanardR", V(0.9, 0.12, 0.65), at(3.0, -0.28, -7.65, rot(0, 12, 8)), BLUE) for _, def in ipairs(WHEEL_DEFS) do local s = 1 if def.x < 0 then s = -1 end add("Flare" .. def.name, V(1.1, 1.1, 4.3), at(s * 3.3, 0.3, def.z), ORANGE) end for _, s in ipairs({-1, 1}) do add("Door", V(0.9, 1.05, 4.6), at(s * 3.15, 0.15, -0.1), ORANGE) -- Blue lower side panel with the silver diagonal M3 GTR racing slash add("BlueSideLivery", V(0.14, 0.82, 5.15), at(s * 3.66, 0.34, 0.15), BLUE) add("SilverSideSlash", V(0.17, 0.18, 4.9), at(s * 3.76, 0.66, 0.15, rot(0, 0, s * 24)), SILVER, Enum.Material.SmoothPlastic) add("BlueRearQuarter", V(0.14, 0.72, 2.0), at(s * 3.68, 0.42, 5.05), RACING_BLUE) add("Rocker", V(0.5, 0.25, 6.4), at(s * 3.2, -0.6, 0), BLACK) add("MirrorShell", V(0.6, 0.4, 0.9), at(s * 3.2, 1.35, -1.15), ORANGE) add("MirrorArm", V(0.5, 0.12, 0.12), at(s * 2.9, 1.25, -1.3), BLACK) add("SideGlass", V(0.1, 1.3, 4.9), at(s * 2.5, 1.8, 0.65), GLASS, Enum.Material.Glass, {Transparency = 0.45, Reflectance = 0.2}) add("Belt", V(0.3, 0.35, 5.6), at(s * 2.65, 1.05, 0.7), ORANGE) add("BPillar", V(0.3, 1.4, 0.4), at(s * 2.5, 1.8, 0.8), ORANGE) add("APillar", V(0.3, 0.18, 3.0), at(s * 2.62, 1.8, -0.73, rot(-32, 0, 0)), ORANGE) add("CPillar", V(0.55, 0.2, 2.6), at(s * 2.55, 1.95, 4.25, rot(31, 0, 0)), ORANGE) add("HoodVent", V(1.3, 0.06, 1.4), at(s * 1.35, 1.04, -4.8, rot(-5, 0, 0)), BLACK) add("SeatBase", V(1.5, 0.3, 1.7), at(s * 1.2, 0.8, 1.1), DARK) add("SeatBack", V(1.5, 1.6, 0.3), at(s * 1.2, 1.6, 1.9, rot(8, 0, 0)), DARK) add("WingStand", V(0.28, 1.35, 0.55), at(s * 1.9, 1.95, 6.2), BLACK) add("WingPlate", V(0.14, 0.9, 1.9), at(s * 3.3, 2.7, 6.3), ORANGE) add("SkirtGlow", V(0.2, 0.1, 10), at(s * 2.7, -0.72, 0), Color3.fromRGB(25, 85, 210), Enum.Material.Neon, {Transparency = 1}) end add("Hood", V(5.4, 0.28, 5.4), at(0, 0.92, -4.2, rot(-5, 0, 0)), ORANGE) -- Twin blue hood fields, leaving the silver center section visible add("HoodBlueL", V(1.45, 0.07, 5.0), at(-1.82, 1.105, -4.15, rot(-5, 0, 0)), BLUE) add("HoodBlueR", V(1.45, 0.07, 5.0), at(1.82, 1.105, -4.15, rot(-5, 0, 0)), BLUE) add("Cowl", V(5.4, 0.35, 0.6), at(0, 1.08, -1.7), BLACK) add("Windshield", V(5.3, 0.12, 3.0), at(0, 1.8, -0.73, rot(-32, 0, 0)), GLASS, Enum.Material.Glass, {Transparency = 0.4, Reflectance = 0.2}) add("Roof", V(5.0, 0.22, 2.7), at(0, 2.6, 1.9), ORANGE) add("RoofBlue", V(4.45, 0.045, 2.35), at(0, 2.735, 1.9), BLUE) add("RearWindow", V(5.0, 0.12, 2.5), at(0, 1.9, 4.33, rot(31, 0, 0)), GLASS, Enum.Material.Glass, {Transparency = 0.4, Reflectance = 0.2}) add("RearDeck", V(5.4, 0.4, 3.0), at(0, 1.05, 6.1), ORANGE) add("TailPanel", V(5.6, 0.55, 0.35), at(0, 0.62, 7.8), BLACK) add("Dash", V(4.6, 0.5, 1.0), at(0, 1.15, -1.3), DARK) add("Floor", V(5.0, 0.15, 5.2), at(0, 0.6, 0.5), BLACK) -- Front end -- Twin kidney grille openings, separated by a narrow silver center bar add("KidneyGrilleL", V(0.82, 0.62, 0.14), at(-0.48, 0.22, -8.035), BLACK) add("KidneyGrilleR", V(0.82, 0.62, 0.14), at(0.48, 0.22, -8.035), BLACK) for _, x in ipairs({-0.48, 0.48}) do for i = -2, 2 do add("KidneySlat", V(0.055, 0.48, 0.035), at(x + i * 0.13, 0.22, -8.12), CHROME) end end add("GrilleCenterBar", V(0.12, 0.62, 0.16), at(0, 0.22, -8.04), SILVER) add("LowerIntake", V(4.4, 0.4, 0.12), at(0, -0.25, -8.02), BLACK) for _, s in ipairs({-1, 1}) do add("HeadHousing", V(1.9, 0.5, 0.4), at(s * 2.15, 0.6, -7.7), BLACK) local lens = add("HeadLens", V(1.5, 0.32, 0.1), at(s * 2.15, 0.6, -7.98), DIM_WHITE) local spot = new("SpotLight", { Face = Enum.NormalId.Front, Brightness = 5, Range = 90, Angle = 75, Color = Color3.fromRGB(255, 240, 210), Enabled = false, }, lens) table.insert(car.headLenses, lens) table.insert(car.headLights, spot) end -- Rear end for _, x in ipairs({-2.2, -1.0, 1.0, 2.2}) do add("TailRing", V(0.2, 1.2, 1.2), at(x, 0.65, 7.93, rot(0, 90, 0)), BLACK, nil, {Shape = CYL}) local lamp = add("TailLamp", V(0.25, 0.95, 0.95), at(x, 0.65, 7.99, rot(0, 90, 0)), DIM_RED, nil, {Shape = CYL}) local glow = new("PointLight", {Color = Color3.fromRGB(255, 20, 20), Range = 10, Brightness = 0, Enabled = false}, lamp) table.insert(car.tailLamps, lamp) table.insert(car.tailLights, glow) end for _, s in ipairs({-1, 1}) do local rev = add("ReverseLamp", V(0.2, 0.45, 0.45), at(s * 1.6, 0.05, 8.0, rot(0, 90, 0)), DIM_WHITE, nil, {Shape = CYL}) table.insert(car.reverseLamps, rev) add("ExhaustTip", V(0.7, 0.65, 0.65), at(s * 1.9, -0.35, 7.95, rot(0, 90, 0)), CHROME, Enum.Material.Metal, {Shape = CYL}) add("ExhaustInner", V(0.72, 0.42, 0.42), at(s * 1.9, -0.35, 7.97, rot(0, 90, 0)), BLACK, nil, {Shape = CYL}) end local plate = add("Plate", V(1.9, 0.55, 0.08), at(0, -0.15, 8.0), Color3.fromRGB(245, 245, 245)) local plateGui = new("SurfaceGui", {Face = Enum.NormalId.Back, CanvasSize = Vector2.new(240, 70)}, plate) new("TextLabel", { Size = UDim2.new(1, 0, 1, 0), BackgroundTransparency = 1, Text = "M3 GTR", TextColor3 = Color3.fromRGB(20, 20, 20), TextScaled = true, Font = Enum.Font.GothamBlack, }, plateGui) -- Spoiler (big GT wing) add("WingBlade", V(6.6, 0.2, 1.6), at(0, 2.7, 6.3, rot(-7, 0, 0)), SILVER) add("WingBlueStripe", V(6.45, 0.045, 0.32), at(0, 2.82, 6.3, rot(-7, 0, 0)), BLUE) add("WingFlap", V(6.6, 0.12, 0.14), at(0, 2.84, 7.05), BLACK) -- Interior wheel add("SteeringWheel", V(0.14, 1.15, 1.15), at(-1.2, 1.5, -0.1, rot(-25, 0, 0) * rot(0, 90, 0)), BLACK, nil, {Shape = CYL}) -- Underglow (hidden until G) add("FrontGlow", V(4.8, 0.1, 0.2), at(0, -0.72, -6), Color3.fromRGB(25, 85, 210), Enum.Material.Neon, {Transparency = 1}) add("RearGlow", V(4.8, 0.1, 0.2), at(0, -0.72, 6), Color3.fromRGB(25, 85, 210), Enum.Material.Neon, {Transparency = 1}) for _, p in ipairs(model:GetChildren()) do if p.Name == "SkirtGlow" or p.Name == "FrontGlow" or p.Name == "RearGlow" then table.insert(car.underglow, p) end end car.underglowLight = new("PointLight", {Color = Color3.fromRGB(25, 85, 210), Range = 14, Brightness = 3, Enabled = false}, chassis) ---------------- Exhaust flames ---------------- for _, s in ipairs({-1, 1}) do local att = new("Attachment", {CFrame = at(s * 1.9, -0.35, 8.4, rot(90, 0, 0))}, chassis) local flame = new("ParticleEmitter", { Texture = "rbxasset://textures/particles/fire_main.dds", Rate = 0, Lifetime = NumberRange.new(0.12, 0.28), Speed = NumberRange.new(18, 32), SpreadAngle = Vector2.new(6, 6), LightEmission = 1, LightInfluence = 0, Size = NumberSequence.new({NumberSequenceKeypoint.new(0, 1.3), NumberSequenceKeypoint.new(1, 0)}), Transparency = NumberSequence.new({NumberSequenceKeypoint.new(0, 0), NumberSequenceKeypoint.new(1, 1)}), Color = ColorSequence.new({ ColorSequenceKeypoint.new(0, Color3.fromRGB(90, 170, 255)), ColorSequenceKeypoint.new(0.35, Color3.fromRGB(210, 225, 255)), ColorSequenceKeypoint.new(1, Color3.fromRGB(25, 65, 180)), }), Rotation = NumberRange.new(0, 360), Enabled = true, }, att) table.insert(car.flames, flame) end ---------------- Wheels ---------------- for _, def in ipairs(WHEEL_DEFS) do local out = 1 if def.x < 0 then out = -1 end local w = { name = def.name, front = def.front, mount = Vector3.new(def.x, MOUNT_Y, def.z), dist = REST_DIST, visDist = REST_DIST, spin = 0, spinRate = 0, grounded = false, skid = false, N = 0, } local hubOffset = CFrame.new(w.mount - Vector3.new(0, REST_DIST - WHEEL_R, 0)) local hub = Instance.new("Part") hub.Name = "Hub" .. def.name hub.Size = Vector3.new(0.3, 0.3, 0.3) hub.Transparency = 1 hub.CanCollide = false hub.CanQuery = false hub.CanTouch = false hub.Massless = true hub.CFrame = chassis.CFrame * hubOffset hub.Parent = model local hubJoint = Instance.new("Weld") hubJoint.Part0 = chassis hubJoint.Part1 = hub hubJoint.C0 = hubOffset hubJoint.Parent = hub local spin = Instance.new("Part") spin.Name = "Spin" .. def.name spin.Size = Vector3.new(0.3, 0.3, 0.3) spin.Transparency = 1 spin.CanCollide = false spin.CanQuery = false spin.CanTouch = false spin.Massless = true spin.CFrame = chassis.CFrame * hubOffset spin.Parent = model local spinJoint = Instance.new("Weld") spinJoint.Part0 = hub spinJoint.Part1 = spin spinJoint.C0 = CFrame.new() spinJoint.Parent = spin add("Tire", V(1.0, WHEEL_R * 2, WHEEL_R * 2), hubOffset, Color3.fromRGB(24, 24, 24), nil, {Shape = CYL}, spin) add("RimFace", V(0.85, 1.9, 1.9), hubOffset * CFrame.new(out * 0.1, 0, 0), Color3.fromRGB(70, 70, 75), Enum.Material.Metal, {Shape = CYL}, spin) add("BrakeDisc", V(0.12, 1.5, 1.5), hubOffset * CFrame.new(-out * 0.2, 0, 0), Color3.fromRGB(120, 120, 125), Enum.Material.Metal, {Shape = CYL}, spin) for i = 0, 4 do add("Spoke", V(0.2, 1.75, 0.32), hubOffset * CFrame.new(out * 0.55, 0, 0) * rot(i * 36, 0, 0), Color3.fromRGB(225, 225, 230), Enum.Material.Metal, nil, spin) end add("Cap", V(0.25, 0.5, 0.5), hubOffset * CFrame.new(out * 0.68, 0, 0), ORANGE, nil, {Shape = CYL}, spin) add("Caliper", V(0.25, 0.55, 0.8), hubOffset * CFrame.new(-out * 0.2, 0.8, 0), Color3.fromRGB(230, 60, 20), nil, nil, hub) -- Ground contact point (skid marks + tire smoke) local contact = Instance.new("Part") contact.Name = "Contact" .. def.name contact.Size = Vector3.new(0.2, 0.2, 0.2) contact.Transparency = 1 contact.CanCollide = false contact.CanQuery = false contact.CanTouch = false contact.Massless = true contact.CFrame = chassis.CFrame * CFrame.new(w.mount - Vector3.new(0, REST_DIST, 0)) contact.Parent = model local contactJoint = Instance.new("Weld") contactJoint.Part0 = chassis contactJoint.Part1 = contact contactJoint.C0 = CFrame.new(w.mount - Vector3.new(0, REST_DIST, 0)) contactJoint.Parent = contact local a0 = new("Attachment", {Position = Vector3.new(-0.55, 0, 0)}, contact) local a1 = new("Attachment", {Position = Vector3.new(0.55, 0, 0)}, contact) local smokeAtt = new("Attachment", {Position = Vector3.new(0, 0.3, 0)}, contact) w.trail = new("Trail", { Attachment0 = a0, Attachment1 = a1, Lifetime = 6, MinLength = 0.1, FaceCamera = false, LightEmission = 0, Color = ColorSequence.new(Color3.fromRGB(10, 10, 10)), Transparency = NumberSequence.new({NumberSequenceKeypoint.new(0, 0.25), NumberSequenceKeypoint.new(1, 1)}), Enabled = false, }, contact) w.smoke = new("ParticleEmitter", { Texture = "rbxasset://textures/particles/smoke_main.dds", Rate = 0, Lifetime = NumberRange.new(0.8, 1.6), Speed = NumberRange.new(2, 7), SpreadAngle = Vector2.new(35, 35), Acceleration = Vector3.new(0, 4, 0), Drag = 1.5, LockedToPart = false, LightEmission = 0, LightInfluence = 1, Rotation = NumberRange.new(0, 360), RotSpeed = NumberRange.new(-60, 60), Size = NumberSequence.new({NumberSequenceKeypoint.new(0, 2), NumberSequenceKeypoint.new(1, 8)}), Transparency = NumberSequence.new({NumberSequenceKeypoint.new(0, 0.55), NumberSequenceKeypoint.new(1, 1)}), Color = ColorSequence.new({ ColorSequenceKeypoint.new(0, Color3.fromRGB(235, 235, 235)), ColorSequenceKeypoint.new(1, Color3.fromRGB(150, 150, 150)), }), Enabled = true, }, smokeAtt) w.hubJoint = hubJoint w.spinJoint = spinJoint w.contactJoint = contactJoint table.insert(car.wheels, w) end car.engine = makeSound(chassis, CONFIG.engineSoundId, true, 0.6) car.horn = makeSound(chassis, CONFIG.hornSoundId, false, 0.8) chassis.Anchored = false chassis.AssemblyLinearVelocity = Vector3.zero chassis.AssemblyAngularVelocity = Vector3.zero return car end ---------------------------------------------------------------- -- Input ---------------------------------------------------------------- local function isDown(code) return UserInputService:IsKeyDown(code) end local function readInput() local i = {fwd = false, back = false, left = false, right = false, hand = false, boost = false} if UserInputService:GetFocusedTextBox() then return i end i.fwd = isDown(Enum.KeyCode.W) or isDown(Enum.KeyCode.Up) i.back = isDown(Enum.KeyCode.S) or isDown(Enum.KeyCode.Down) i.left = isDown(Enum.KeyCode.A) or isDown(Enum.KeyCode.Left) i.right = isDown(Enum.KeyCode.D) or isDown(Enum.KeyCode.Right) i.hand = isDown(Enum.KeyCode.Space) i.boost = isDown(Enum.KeyCode.LeftShift) return i end ---------------------------------------------------------------- -- Physics ---------------------------------------------------------------- local function physicsStep(dt) if not car or not car.chassis.Parent then return end if dt > 0.05 then dt = 0.05 end if dt <= 0 then return end local chassis = car.chassis local cf = chassis.CFrame local up = cf.UpVector local fwd = cf.LookVector local right = cf.RightVector local vel = chassis.AssemblyLinearVelocity local mass = chassis.AssemblyMass local gravity = workspace.Gravity local fSpeed = vel:Dot(fwd) local speed = vel.Magnitude -- Input local inp = {fwd = false, back = false, left = false, right = false, hand = false, boost = false} if driving then inp = readInput() end local driveInput = 0 local brakeAmount = 0 if inp.fwd and not inp.back then if fSpeed < -3 then brakeAmount = 1 else driveInput = 1 end elseif inp.back and not inp.fwd then if fSpeed > 3 then brakeAmount = 1 else driveInput = -1 end elseif inp.fwd and inp.back then brakeAmount = 1 end local hand = 0 if inp.hand then hand = 1 end local parked = not driving -- Steering local rawSteer = 0 if inp.left then rawSteer = rawSteer + 1 end if inp.right then rawSteer = rawSteer - 1 end local steerRate = 7 if rawSteer == 0 then steerRate = 10 end car.steerInput = car.steerInput + (rawSteer - car.steerInput) * math.min(1, steerRate * dt) local vLatBody = vel:Dot(right) local slip = math.atan2(vLatBody, math.max(math.abs(fSpeed), 1)) local maxSteer = math.rad(MAX_STEER_LOW + (MAX_STEER_HIGH - MAX_STEER_LOW) * math.clamp(speed / 170, 0, 1)) local steerAngle = car.steerInput * maxSteer if fSpeed > 8 and speed > 15 then steerAngle = steerAngle + (-slip) * 1.1 * 0.55 -- counter-steer assist end steerAngle = math.clamp(steerAngle, -math.rad(38), math.rad(38)) car.steerAngle = steerAngle -- Rear grip (drift) local targetRear = 1 if hand > 0 and speed > 18 then targetRear = 0.38 elseif driveInput > 0 and math.abs(car.steerInput) > 0.55 and speed > 50 then targetRear = 0.62 end if car.drifting and driveInput > 0 then targetRear = math.min(targetRear, 0.55) end local gripRate = 2.2 if targetRear < car.rearGrip then gripRate = 9 end car.rearGrip = car.rearGrip + (targetRear - car.rearGrip) * math.min(1, gripRate * dt) -- Nitro local boosting = inp.boost and car.nitro > 1 and driveInput > 0 and driving if boosting then car.nitro = math.max(0, car.nitro - 26 * dt) else car.nitro = math.min(100, car.nitro + 4 * dt) end car.boosting = boosting -- Gearbox if driveInput >= 0 and fSpeed > -2 then local g = car.gear if g < #GEAR_MAX and fSpeed > GEAR_MAX[g] * 0.93 then g = g + 1 car.shiftTimer = 0.14 if driveInput > 0 then car.popRequest = true end elseif g > 1 and fSpeed < GEAR_MAX[g - 1] * 0.62 then g = g - 1 end car.gear = g end car.shiftTimer = math.max(0, car.shiftTimer - dt) -- Engine output local accelNow = 0 if driveInput > 0 then local g = car.gear local ratio = math.clamp(fSpeed / GEAR_MAX[g], 0, 1) accelNow = GEAR_ACCEL[g] * (0.6 + 0.4 * (1 - ratio * ratio)) local topNow = GEAR_MAX[#GEAR_MAX] if boosting then accelNow = accelNow * 1.7 topNow = topNow * 1.2 end if car.shiftTimer > 0 then accelNow = 0 end if fSpeed > topNow then accelNow = 0 end elseif driveInput < 0 then if fSpeed > -REVERSE_MAX then accelNow = REVERSE_ACCEL end end -- RPM (for HUD / sound / flames) local gRatio = math.clamp(math.abs(fSpeed) / GEAR_MAX[car.gear], 0, 1) local targetRpm = math.max(gRatio, 0.12) if driveInput ~= 0 and math.abs(fSpeed) < 25 then targetRpm = math.max(targetRpm, 0.45) end if car.shiftTimer > 0 then targetRpm = targetRpm * 0.8 end car.rpm = car.rpm + (targetRpm - car.rpm) * math.min(1, 10 * dt) if car.prevDrive > 0 and driveInput == 0 and car.rpm > 0.75 then car.popRequest = true end car.prevDrive = driveInput -- Suspension + tires local k = (mass * gravity / 4) / (SPRING_LEN - REST_DIST) local c = 2 * 0.55 * math.sqrt(k * mass / 4) local steerRot = CFrame.fromAxisAngle(up, steerAngle) local groundedCount = 0 for _, w in ipairs(car.wheels) do local mountWorld = cf:PointToWorldSpace(w.mount) local result = workspace:Raycast(mountWorld, -up * RAY_LEN, rayParams) if result then groundedCount = groundedCount + 1 w.grounded = true w.dist = result.Distance local comp = SPRING_LEN - w.dist local pointVel = chassis:GetVelocityAtPosition(mountWorld) local F = 0 if comp > 0 then F = math.max(0, k * comp - c * pointVel:Dot(up)) end w.N = F chassis:ApplyImpulseAtPosition(up * (F * dt), mountWorld) -- Tire frame local n = result.Normal local dirF = fwd if w.front then dirF = steerRot:VectorToWorldSpace(fwd) end dirF = dirF - n * dirF:Dot(n) if dirF.Magnitude < 0.001 then dirF = fwd end dirF = dirF.Unit local dirR = dirF:Cross(n) local contactVel = chassis:GetVelocityAtPosition(result.Position) local vLong = contactVel:Dot(dirF) local vLat = contactVel:Dot(dirR) -- Longitudinal: drive, brakes, handbrake, rolling resistance local drive = 0 if not w.front and driveInput ~= 0 then drive = mass * accelNow * driveInput / 2 end local brakeCap = 0 if parked then brakeCap = mass * 60 / 4 elseif brakeAmount > 0 then brakeCap = mass * BRAKE_DECEL / 4 * brakeAmount elseif driveInput == 0 then brakeCap = mass * ROLL_DECEL / 4 end local brakeF = 0 if brakeCap > 0 then brakeF = math.clamp(-vLong * (mass / 4) / dt, -brakeCap, brakeCap) end local handF = 0 if not w.front and hand > 0 then local handCap = mass * HAND_DECEL / 2 * hand handF = math.clamp(-vLong * (mass / 4) / dt, -handCap, handCap) end local Flong = drive + brakeF + handF local Flat = -vLat * (mass / 4) / dt * GRIP_GAIN -- Friction circle local mu = MU_FRONT if not w.front then mu = MU_REAR * car.rearGrip end local maxF = mu * w.N local mag = math.sqrt(Flat * Flat + Flong * Flong) local saturated = false if mag > maxF then saturated = true if mag > 0 then local s = maxF / mag Flat = Flat * s Flong = Flong * s end end chassis:ApplyImpulseAtPosition((dirF * Flong + dirR * Flat) * (dt), mountWorld) -- Effects data w.skid = (saturated and speed > 12) or (not w.front and hand > 0 and math.abs(vLong) > 10) w.spinRate = vLong / WHEEL_R if not w.front and driveInput > 0 and saturated and speed < 80 then w.spinRate = w.spinRate + 30 * (1 - speed / 90) end if not w.front and hand > 0 then w.spinRate = 0 end else w.grounded = false w.dist = RAY_LEN w.N = 0 w.skid = false w.spinRate = w.spinRate * (1 - math.min(1, 1.5 * dt)) end end -- Aero chassis:ApplyImpulse(-vel * ((DRAG_LIN + DRAG_QUAD * speed) * mass * dt)) chassis:ApplyImpulse(-up * (DOWNFORCE * speed * speed * mass * dt)) -- Handbrake kick (helps start a drift) if hand > 0 and groundedCount >= 2 and speed > 20 then chassis:ApplyAngularImpulse(up * (car.steerInput * mass * 20 * 1.6 * dt)) end -- Airborne stabilising if groundedCount == 0 then local axis = up:Cross(Vector3.yAxis) chassis:ApplyAngularImpulse(axis * (mass * 20 * 0.8 * dt)) local angVel = chassis.AssemblyAngularVelocity chassis:ApplyAngularImpulse(-angVel * (mass * 20 * math.min(1, 1.2 * dt))) end -- Drift detection / scoring local slipDeg = math.deg(math.abs(slip)) car.speed = speed car.fSpeed = fSpeed car.slipDeg = slipDeg car.brakeAmount = brakeAmount car.throttle = driveInput car.reversing = fSpeed < -1.5 or driveInput < 0 car.drifting = groundedCount >= 2 and speed > 28 and slipDeg > 14 and fSpeed > 0 and driving local d = car.drift if car.drifting then d.active = true d.endTimer = 0 d.time = d.time + dt d.combo = math.min(8, 1 + math.floor(d.time / 3)) d.score = d.score + dt * speed * slipDeg * 0.08 * d.combo car.nitro = math.min(100, car.nitro + 10 * dt) elseif d.active then d.endTimer = d.endTimer + dt if d.endTimer > 1.0 then if d.score > 50 then car.totalScore = car.totalScore + d.score hud.flash = 2.0 hud.driftSub.Text = "BANKED +" .. commas(d.score) .. " TOTAL " .. commas(car.totalScore) end d.active = false d.time = 0 d.score = 0 d.combo = 1 d.endTimer = 0 end end end ---------------------------------------------------------------- -- Visuals (wheels, lights, smoke, HUD, sound) ---------------------------------------------------------------- local function setLights(carRef, head, brake, rev, glow) local ls = carRef.lightState if ls.head ~= head then ls.head = head for i, lens in ipairs(carRef.headLenses) do if head then lens.Material = Enum.Material.Neon lens.Color = Color3.fromRGB(255, 244, 214) else lens.Material = Enum.Material.SmoothPlastic lens.Color = Color3.fromRGB(190, 190, 185) end carRef.headLights[i].Enabled = head end end local tailKey = brake and 2 or (head and 1 or 0) if ls.brake ~= tailKey then ls.brake = tailKey for i, lamp in ipairs(carRef.tailLamps) do local glowLight = carRef.tailLights[i] if tailKey == 2 then lamp.Material = Enum.Material.Neon lamp.Color = Color3.fromRGB(255, 25, 25) glowLight.Enabled = true glowLight.Brightness = 3 elseif tailKey == 1 then lamp.Material = Enum.Material.Neon lamp.Color = Color3.fromRGB(170, 0, 0) glowLight.Enabled = true glowLight.Brightness = 1 else lamp.Material = Enum.Material.SmoothPlastic lamp.Color = Color3.fromRGB(110, 15, 15) glowLight.Enabled = false end end end if ls.rev ~= rev then ls.rev = rev for _, lamp in ipairs(carRef.reverseLamps) do if rev then lamp.Material = Enum.Material.Neon lamp.Color = Color3.fromRGB(255, 255, 255) else lamp.Material = Enum.Material.SmoothPlastic lamp.Color = Color3.fromRGB(190, 190, 185) end end end if ls.glow ~= glow then ls.glow = glow for _, p in ipairs(carRef.underglow) do if glow then p.Transparency = 0 else p.Transparency = 1 end end carRef.underglowLight.Enabled = glow end end local function visualStep(dt) if not car or not car.chassis.Parent then return end local speedKmh = car.speed * KMH for _, w in ipairs(car.wheels) do w.visDist = w.visDist + (w.dist - w.visDist) * math.min(1, dt * 25) w.spin = w.spin - w.spinRate * dt local steerYaw = 0 if w.front then steerYaw = car.steerAngle end local drop = w.visDist - WHEEL_R w.hubJoint.C0 = CFrame.new(w.mount.X, w.mount.Y - drop, w.mount.Z) * CFrame.Angles(0, steerYaw, 0) w.spinJoint.C0 = CFrame.Angles(w.spin, 0, 0) w.contactJoint.C0 = CFrame.new(w.mount.X, w.mount.Y - w.visDist, w.mount.Z) if w.skid and w.grounded then w.smoke.Rate = math.clamp(25 + car.speed * 0.8, 0, 110) w.trail.Enabled = true else w.smoke.Rate = 0 w.trail.Enabled = false end end -- Lights local braking = car.brakeAmount > 0 or (car.throttle == 0 and false) setLights(car, car.lightsOn, braking, car.reversing and driving, car.glowOn) -- Exhaust: nitro flames + backfire pops for _, flame in ipairs(car.flames) do if car.boosting then flame.Rate = 200 else flame.Rate = 0 end if car.popRequest then flame:Emit(math.random(4, 9)) end end car.popRequest = false -- Engine sound if car.engine then if driving then if not car.engine.IsPlaying then car.engine:Play() end car.engine.PlaybackSpeed = 0.5 + car.rpm * 1.6 car.engine.Volume = 0.35 + math.abs(car.throttle) * 0.45 elseif car.engine.IsPlaying then car.engine:Stop() end end -- Keep the driver seated if driving and savedHumanoid and savedHumanoid.Parent then if not savedHumanoid.Sit then savedHumanoid.Sit = true end end -- HUD hud.panel.Visible = driving hud.hints.Visible = driving and hudVisibleHints if driving then hud.speed.Text = tostring(math.floor(speedKmh + 0.5)) local gearText = tostring(car.gear) if car.fSpeed < -1.5 then gearText = "R" elseif car.speed < 1 and car.throttle == 0 then gearText = "N" end hud.gear.Text = gearText hud.rpmClip.Size = UDim2.new(math.clamp(car.rpm, 0, 1), 0, 1, 0) hud.nitro.Size = UDim2.new(math.clamp(car.nitro / 100, 0, 1), 0, 1, 0) if car.boosting then hud.nitro.BackgroundColor3 = Color3.fromRGB(140, 220, 255) else hud.nitro.BackgroundColor3 = Color3.fromRGB(70, 170, 255) end local d = car.drift if d.active then hud.drift.Text = "DRIFT " .. commas(d.score) hud.driftSub.Text = "x" .. d.combo .. " " .. math.floor(car.slipDeg) .. " deg" hud.driftSub.TextTransparency = 0 hud.flash = 0 elseif hud.flash > 0 then hud.flash = hud.flash - dt hud.drift.Text = "" hud.driftSub.TextTransparency = math.clamp(1 - hud.flash, 0, 1) else hud.drift.Text = "" hud.driftSub.Text = "" end else hud.drift.Text = "" hud.driftSub.Text = "" end end ---------------------------------------------------------------- -- Camera ---------------------------------------------------------------- local CAM_MODES = 3 local function cameraStep(dt) if not car or not driving then return end local cam = workspace.CurrentCamera if not cam then return end cam.CameraType = Enum.CameraType.Scriptable local chassis = car.chassis local cf = chassis.CFrame local pos = cf.Position local vel = chassis.AssemblyLinearVelocity local speed = vel.Magnitude local speedF = math.clamp(speed / 200, 0, 1) local targetFov = 68 + speedF * 20 if car.boosting then targetFov = targetFov + 10 end camState.fov = camState.fov + (targetFov - camState.fov) * math.min(1, 5 * dt) if camState.mode == 3 then cam.CFrame = cf * CFrame.new(-1.2, 2.0, 0.9) cam.FieldOfView = camState.fov + 8 return end local flatLook = Vector3.new(cf.LookVector.X, 0, cf.LookVector.Z) if flatLook.Magnitude < 0.05 then flatLook = Vector3.new(0, 0, -1) else flatLook = flatLook.Unit end local dir = flatLook local flatVel = Vector3.new(vel.X, 0, vel.Z) if flatVel.Magnitude > 12 and vel:Dot(cf.LookVector) > 0 then local blended = flatLook * 0.5 + flatVel.Unit * 0.5 if blended.Magnitude > 0.05 then dir = blended.Unit end end local targetYaw = math.atan2(-dir.X, -dir.Z) local delta = (targetYaw - camState.yaw + math.pi) % (2 * math.pi) - math.pi camState.yaw = camState.yaw + delta * (1 - math.exp(-5.5 * dt)) if not camState.rmb then local decay = math.exp(-3 * dt) camState.orbitYaw = camState.orbitYaw * decay camState.orbitPitch = camState.orbitPitch * decay end local base = CFrame.Angles(0, camState.yaw + camState.orbitYaw, 0) local dist = 16.5 local height = 6.2 if camState.mode == 2 then dist = 24 height = 9.5 end dist = dist + speedF * 3.5 height = height + camState.orbitPitch * 14 local desired = pos + base:VectorToWorldSpace(Vector3.new(0, height, dist)) -- Don't let the camera clip into walls local origin = pos + Vector3.new(0, 2.5, 0) local toCam = desired - origin local hit = workspace:Raycast(origin, toCam, rayParams) if hit then desired = origin + toCam.Unit * math.max(2, hit.Distance - 0.8) end if not camState.pos then camState.pos = desired end camState.pos = camState.pos:Lerp(desired, 1 - math.exp(-13 * dt)) local lookTarget = pos + Vector3.new(0, 2.4, 0) + base:VectorToWorldSpace(Vector3.new(0, 0, -9)) local camCF = CFrame.lookAt(camState.pos, lookTarget) local shake = speedF * 0.12 if car.boosting then shake = shake + 0.35 end if shake > 0 then local amp = shake * 0.006 camCF = camCF * CFrame.Angles((math.random() - 0.5) * amp * 2, (math.random() - 0.5) * amp * 2, 0) end cam.CFrame = camCF cam.FieldOfView = camState.fov end ---------------------------------------------------------------- -- Enter / exit / spawn / destroy ---------------------------------------------------------------- local function setControlsEnabled(enabled) pcall(function() local scripts = LocalPlayer:FindFirstChild("PlayerScripts") local moduleScript = scripts and scripts:FindFirstChild("PlayerModule") if moduleScript then local controls = require(moduleScript):GetControls() if enabled then controls:Enable() else controls:Disable() end end end) end local function setDriverHidden(char, hidden) if hidden then for _, inst in ipairs(char:GetDescendants()) do if inst:IsA("BasePart") or inst:IsA("Decal") then if hiddenParts[inst] == nil then hiddenParts[inst] = inst.Transparency end inst.Transparency = 1 end end else for inst, original in pairs(hiddenParts) do if inst.Parent then inst.Transparency = original end end table.clear(hiddenParts) end end local function exitCar() if not driving then return end driving = false pcall(function() RunService:UnbindFromRenderStep("M3GTRCamera") end) local char = LocalPlayer.Character local hrp = char and char:FindFirstChild("HumanoidRootPart") local hum = char and char:FindFirstChildOfClass("Humanoid") if hrp then local weld = hrp:FindFirstChild("M3GTRSeatWeld") if weld then weld:Destroy() end if car and car.chassis.Parent then hrp.CFrame = car.chassis.CFrame * CFrame.new(-5.5, 1.5, 1.2) hrp.AssemblyLinearVelocity = Vector3.zero end end if hum and savedHumanoid == hum then hum.Sit = false hum.WalkSpeed = hum.WalkSpeed if hum.Parent then hum.AutoRotate = true end end if savedHumanoid and savedHumanoid.Parent and savedHumanoid.Parent == char then savedHumanoid.WalkSpeed = savedHumanoid:GetAttribute("M3GTRWalk") or 16 savedHumanoid.JumpPower = savedHumanoid:GetAttribute("M3GTRJump") or 50 savedHumanoid:ChangeState(Enum.HumanoidStateType.GettingUp) end savedHumanoid = nil if char then setDriverHidden(char, false) end setControlsEnabled(true) local cam = workspace.CurrentCamera if cam then cam.CameraType = Enum.CameraType.Custom if hum then cam.CameraSubject = hum end cam.FieldOfView = originalFov end end local function enterCar() if driving or not car then return end local char = LocalPlayer.Character local hrp = char and char:FindFirstChild("HumanoidRootPart") local hum = char and char:FindFirstChildOfClass("Humanoid") if not hrp or not hum or hum.Health <= 0 then return end if (car.chassis.Position - hrp.Position).Magnitude > 22 then return end driving = true savedHumanoid = hum hum:SetAttribute("M3GTRWalk", hum.WalkSpeed) hum:SetAttribute("M3GTRJump", hum.JumpPower) setControlsEnabled(false) hum.WalkSpeed = 0 hum.JumpPower = 0 hum.AutoRotate = false hrp.CFrame = car.chassis.CFrame * CFrame.new(-1.2, 1.9, 1.3) hrp.AssemblyLinearVelocity = Vector3.zero local weld = Instance.new("WeldConstraint") weld.Name = "M3GTRSeatWeld" weld.Part0 = hrp weld.Part1 = car.chassis weld.Parent = hrp pcall(function() hum.Sit = true hum:ChangeState(Enum.HumanoidStateType.Seated) end) if CONFIG.hideDriver then setDriverHidden(char, true) end updateRayFilter() local cam = workspace.CurrentCamera if cam then originalFov = cam.FieldOfView camState.fov = originalFov end camState.pos = nil camState.orbitYaw = 0 camState.orbitPitch = 0 local look = car.chassis.CFrame.LookVector camState.yaw = math.atan2(-look.X, -look.Z) pcall(function() RunService:BindToRenderStep("M3GTRCamera", Enum.RenderPriority.Camera.Value + 1, cameraStep) end) end local function destroyCar() if driving then exitCar() end if car then if car.model then car.model:Destroy() end car = nil end end local function spawnCar() destroyCar() local char = LocalPlayer.Character local hrp = char and char:FindFirstChild("HumanoidRootPart") local base = CFrame.new(0, 10, 0) if hrp then base = hrp.CFrame end local flatLook = Vector3.new(base.LookVector.X, 0, base.LookVector.Z) if flatLook.Magnitude < 0.01 then flatLook = Vector3.new(0, 0, -1) end flatLook = flatLook.Unit local pos = base.Position + flatLook * 14 local groundParams = RaycastParams.new() groundParams.FilterType = Enum.RaycastFilterType.Exclude if char then groundParams.FilterDescendantsInstances = {char} end local hit = workspace:Raycast(pos + Vector3.new(0, 60, 0), Vector3.new(0, -300, 0), groundParams) local y = pos.Y if hit then y = hit.Position.Y + 2.6 end local spawnPos = Vector3.new(pos.X, y, pos.Z) car = buildCar(CFrame.lookAt(spawnPos, spawnPos + flatLook)) updateRayFilter() if CONFIG.autoEnter then task.wait(0.3) enterCar() end end local function resetCar() if not car then return end local cf = car.chassis.CFrame local look = Vector3.new(cf.LookVector.X, 0, cf.LookVector.Z) if look.Magnitude < 0.05 then look = Vector3.new(0, 0, -1) end local p = cf.Position + Vector3.new(0, 4, 0) car.chassis.CFrame = CFrame.lookAt(p, p + look.Unit) car.chassis.AssemblyLinearVelocity = Vector3.zero car.chassis.AssemblyAngularVelocity = Vector3.zero end local function destroyAll() destroyCar() for _, conn in ipairs(connections) do conn:Disconnect() end pcall(function() RunService:UnbindFromRenderStep("M3GTRCamera") end) hud.gui:Destroy() end ---------------------------------------------------------------- -- Connections ---------------------------------------------------------------- table.insert(connections, RunService.PreSimulation:Connect(physicsStep)) table.insert(connections, RunService.RenderStepped:Connect(visualStep)) table.insert(connections, UserInputService.InputBegan:Connect(function(input, gameProcessed) if gameProcessed then return end local key = input.KeyCode if key == Enum.KeyCode.LeftBracket then destroyAll() elseif key == Enum.KeyCode.E then if driving then exitCar() else enterCar() end elseif key == Enum.KeyCode.R then resetCar() elseif key == Enum.KeyCode.T then task.spawn(spawnCar) elseif key == Enum.KeyCode.L then if car then car.lightsOn = not car.lightsOn end elseif key == Enum.KeyCode.G then if car then car.glowOn = not car.glowOn end elseif key == Enum.KeyCode.C then camState.mode = camState.mode + 1 if camState.mode > CAM_MODES then camState.mode = 1 end elseif key == Enum.KeyCode.F1 then hudVisibleHints = not hudVisibleHints elseif key == Enum.KeyCode.H then if car and car.horn then car.horn:Play() end elseif input.UserInputType == Enum.UserInputType.MouseButton2 then camState.rmb = true end end)) table.insert(connections, UserInputService.InputEnded:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton2 then camState.rmb = false end end)) table.insert(connections, UserInputService.InputChanged:Connect(function(input) if camState.rmb and input.UserInputType == Enum.UserInputType.MouseMovement then camState.orbitYaw = camState.orbitYaw - input.Delta.X * 0.006 camState.orbitPitch = math.clamp(camState.orbitPitch + input.Delta.Y * 0.004, -0.6, 1.2) end end)) table.insert(connections, LocalPlayer.CharacterAdded:Connect(function() -- Respawned: make sure we aren't stuck in a "driving" state if driving then driving = false pcall(function() RunService:UnbindFromRenderStep("M3GTRCamera") end) table.clear(hiddenParts) savedHumanoid = nil setControlsEnabled(true) end task.wait(0.5) updateRayFilter() end)) task.spawn(spawnCar)