Tuner v3.6
Key Required

Tuner v3.6

Unrated
00
Lua Scriptâ€ĸ1380 lines (42759 chars)
-- Tuner v3.6
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
if not LocalPlayer then
	warn("[Tuner] No LocalPlayer — run as LocalScript/Executor")
	return
end
local pg = LocalPlayer:FindFirstChild("PlayerGui")
if not pg then
    -- Wait briefly, don't hard fail
	pg = LocalPlayer:WaitForChild("PlayerGui", 5)
	if not pg then
		warn("[Tuner] PlayerGui not found");
		return
	end
end
-- Safe remove old UI — no error if none exists
local old = pg:FindFirstChild("CarTunerUI")
if old then
	pcall(function()
		old:Destroy()
	end)
end
local HttpService = game:GetService("HttpService")

-- ===== _G GLOBAL STORE =====
_G.TunerStored = _G.TunerStored or _G["***"] or nil
if not _G.TunerStored then
	local j = workspace:GetAttribute("***")
	if j and type(j) == "string" and # j > 4 then
		local ok, t = pcall(HttpService.JSONDecode, HttpService, j)
		if ok and type(t) == "table" then
			_G.TunerStored = t
		end
	end
end
local function saveGlobal(tbl)
	_G.TunerStored = tbl
	_G["***"] = tbl
	local ok, json = pcall(HttpService.JSONEncode, HttpService, tbl)
	if ok then
		pcall(function()
			workspace:SetAttribute("***", json)
		end)
	end
end
local function loadGlobal()
	if _G.TunerStored and type(_G.TunerStored) == "table" and next(_G.TunerStored) ~= nil then
		return _G.TunerStored
	end
	if _G["***"] and type(_G["***"]) == "table" and next(_G["***"]) ~= nil then
		return _G["***"]
	end
	local j = workspace:GetAttribute("***")
	if j and type(j) == "string" and # j > 4 then
		local ok, t = pcall(HttpService.JSONDecode, HttpService, j)
		if ok and type(t) == "table" and next(t) ~= nil then
			_G.TunerStored = t;
			return t
		end
	end
	return nil
end
local function findAllCars()
	local t = {}
	for _, o in ipairs(workspace:GetChildren()) do
		local ok = pcall(function()
			return o:FindFirstChild("Tuner") and o:FindFirstChild("DriveSeat")
		end)
		if ok and o:FindFirstChild("Tuner") and o:FindFirstChild("DriveSeat") then
			table.insert(t, o)
		end
	end
	return t
end
local function getClosestCar(cars)
	local char = LocalPlayer.Character
	local hrp = char and char:FindFirstChild("HumanoidRootPart")
	if not hrp then
		return cars[1]
	end
	local best, bestDist = nil, math.huge
	for _, c in ipairs(cars) do
		local seat = c:FindFirstChild("DriveSeat")
		if seat then
			local d = (seat.Position - hrp.Position).Magnitude;
			if d < bestDist then
				bestDist = d;
				best = c
			end
		end
	end
	return best or cars[1]
end
local function getPreferredCar()
	local cars = findAllCars()
	if # cars == 0 then
		return nil
	end
	local want = LocalPlayer.Name .. "sCar"
	local exact = workspace:FindFirstChild(want)
	if exact and exact:FindFirstChild("Tuner") then
		return exact
	end
	local lastName = workspace:GetAttribute("TunerLastCar")
	if lastName then
		local lc = workspace:FindFirstChild(lastName);
		if lc and lc:FindFirstChild("Tuner") then
			return lc
		end
	end
	for _, c in ipairs(cars) do
		if c.Name:lower():find(LocalPlayer.Name:lower(), 1, true) then
			return c
		end
	end
	return getClosestCar(cars)
end
local function getTuner(car)
	if not car then
		return nil
	end
	local m = car:FindFirstChild("Tuner")
	if not m then
		return nil
	end
	local ok, t = pcall(require, m)
	if ok then
		return t
	end
	return nil
end
local currentCar = getPreferredCar()
if not currentCar then
	warn("[Tuner] No vehicle found in workspace");
	return
end
local tuner = getTuner(currentCar)
if not tuner then
	warn("[Tuner] Tuner require failed for " .. currentCar.Name);
	return
end

-- Restore _G tune to current car on open (do not overwrite _G with defaults)
local stored = loadGlobal()
local appliedOnOpen = false
if stored and next(stored) ~= nil then
	local cnt = 0
	for k, v in pairs(stored) do
		if k == "Ratios" and type(v) == "table" and tuner.Ratios then
			for i = 1, 5 do
				if v[i] ~= nil then
					tuner.Ratios[i] = v[i];
					cnt += 1
				end
			end
		elseif tuner[k] ~= nil then
			tuner[k] = v;
			cnt += 1
		end
	end
	if cnt > 0 then
		appliedOnOpen = true;
		print("[Tuner] Restored " .. cnt .. " values from _G to " .. currentCar.Name)
	end
end
local defaults = {}
for k, v in pairs(tuner) do
	if type(v) == "number" or type(v) == "boolean" then
		defaults[k] = v
	end
end
if tuner.Ratios then
	defaults["Ratios"] = {
		tuner.Ratios[1],
		tuner.Ratios[2],
		tuner.Ratios[3],
		tuner.Ratios[4],
		tuner.Ratios[5]
	}
end

-- ===== UI BUILD =====
local gui = Instance.new("ScreenGui");
gui.Name = "CarTunerUI";
gui.ResetOnSpawn = false;
gui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling;
gui.Parent = pg
local main = Instance.new("Frame");
main.Name = "Main";
main.Size = UDim2.fromOffset(500, 580);
main.Position = UDim2.fromScale(0.5, 0.5);
main.AnchorPoint = Vector2.new(0.5, 0.5);
main.BackgroundColor3 = Color3.fromRGB(16, 16, 20);
main.BorderSizePixel = 0;
main.ClipsDescendants = true;
main.Parent = gui
Instance.new("UICorner", main).CornerRadius = UDim.new(0, 16)
local stroke = Instance.new("UIStroke", main);
stroke.Color = Color3.fromRGB(55, 55, 65);
stroke.Thickness = 1.2
local top = Instance.new("Frame", main);
top.Name = "TopBar";
top.Size = UDim2.new(1, 0, 0, 50);
top.BackgroundColor3 = Color3.fromRGB(26, 26, 32);
top.BorderSizePixel = 0
Instance.new("UICorner", top).CornerRadius = UDim.new(0, 16)
local fix = Instance.new("Frame", top);
fix.Size = UDim2.new(1, 0, 0, 14);
fix.Position = UDim2.new(0, 0, 1, - 14);
fix.BackgroundColor3 = top.BackgroundColor3;
fix.BorderSizePixel = 0
local icon = Instance.new("TextLabel", top);
icon.Size = UDim2.fromOffset(36, 36);
icon.Position = UDim2.fromOffset(10, 7);
icon.BackgroundColor3 = Color3.fromRGB(255, 70, 70);
icon.Text = "đŸŽī¸";
icon.TextScaled = true;
Instance.new("UICorner", icon).CornerRadius = UDim.new(0, 9)
local title = Instance.new("TextLabel", top);
title.Position = UDim2.fromOffset(54, 10);
title.Size = UDim2.new(1, - 150, 0, 30);
title.BackgroundTransparency = 1;
title.Text = "Tuner v3.6";
title.Font = Enum.Font.GothamBold;
title.TextSize = 15;
title.TextColor3 = Color3.new(1, 1, 1);
title.TextXAlignment = Enum.TextXAlignment.Left
local btnMin = Instance.new("TextButton", top);
btnMin.Size = UDim2.fromOffset(30, 30);
btnMin.Position = UDim2.new(1, - 72, 0, 10);
btnMin.BackgroundColor3 = Color3.fromRGB(48, 48, 58);
btnMin.Text = "—";
btnMin.Font = Enum.Font.GothamBold;
btnMin.TextSize = 14;
btnMin.TextColor3 = Color3.new(1, 1, 1);
Instance.new("UICorner", btnMin).CornerRadius = UDim.new(0, 8)
local btnClose = Instance.new("TextButton", top);
btnClose.Size = UDim2.fromOffset(30, 30);
btnClose.Position = UDim2.new(1, - 36, 0, 10);
btnClose.BackgroundColor3 = Color3.fromRGB(210, 50, 50);
btnClose.Text = "✕";
btnClose.Font = Enum.Font.GothamBold;
btnClose.TextSize = 14;
btnClose.TextColor3 = Color3.new(1, 1, 1);
Instance.new("UICorner", btnClose).CornerRadius = UDim.new(0, 8)
local carRow = Instance.new("Frame", main);
carRow.Name = "CarRow";
carRow.Position = UDim2.fromOffset(10, 58);
carRow.Size = UDim2.new(1, - 20, 0, 30);
carRow.BackgroundColor3 = Color3.fromRGB(30, 30, 38);
Instance.new("UICorner", carRow).CornerRadius = UDim.new(0, 10)
local carLabel = Instance.new("TextLabel", carRow);
carLabel.Name = "CarLabel";
carLabel.Position = UDim2.fromOffset(10, 0);
carLabel.Size = UDim2.new(1, - 110, 1, 0);
carLabel.BackgroundTransparency = 1;
carLabel.Text = "🚗 " .. currentCar.Name .. (appliedOnOpen and "  ✓ restored" or "");
carLabel.Font = Enum.Font.GothamBold;
carLabel.TextSize = 11;
carLabel.TextColor3 = appliedOnOpen and Color3.fromRGB(0, 220, 120) or Color3.fromRGB(100, 220, 255);
carLabel.TextXAlignment = Enum.TextXAlignment.Left;
carLabel.TextTruncate = Enum.TextTruncate.AtEnd
local btnRefresh = Instance.new("TextButton", carRow);
btnRefresh.Name = "RefreshBtn";
btnRefresh.Size = UDim2.fromOffset(44, 22);
btnRefresh.Position = UDim2.new(1, - 96, 0, 4);
btnRefresh.BackgroundColor3 = Color3.fromRGB(60, 60, 75);
btnRefresh.Text = "🔄";
btnRefresh.Font = Enum.Font.GothamBold;
btnRefresh.TextSize = 13;
btnRefresh.TextColor3 = Color3.new(1, 1, 1);
Instance.new("UICorner", btnRefresh).CornerRadius = UDim.new(0, 6)
local btnPick = Instance.new("TextButton", carRow);
btnPick.Name = "PickBtn";
btnPick.Size = UDim2.fromOffset(44, 22);
btnPick.Position = UDim2.new(1, - 48, 0, 4);
btnPick.BackgroundColor3 = Color3.fromRGB(70, 90, 220);
btnPick.Text = "Select";
btnPick.Font = Enum.Font.GothamBold;
btnPick.TextSize = 10;
btnPick.TextColor3 = Color3.new(1, 1, 1);
Instance.new("UICorner", btnPick).CornerRadius = UDim.new(0, 6)
local dropdown = Instance.new("ScrollingFrame", main);
dropdown.Name = "Dropdown";
dropdown.Position = UDim2.fromOffset(10, 90);
dropdown.Size = UDim2.fromOffset(480, 150);
dropdown.BackgroundColor3 = Color3.fromRGB(24, 24, 30);
dropdown.BorderSizePixel = 0;
dropdown.Visible = false;
dropdown.ZIndex = 10;
dropdown.ScrollBarThickness = 4;
dropdown.AutomaticCanvasSize = Enum.AutomaticSize.Y;
dropdown.CanvasSize = UDim2.new(0, 0, 0, 0)
Instance.new("UICorner", dropdown).CornerRadius = UDim.new(0, 10)
local ddStroke = Instance.new("UIStroke", dropdown);
ddStroke.Color = Color3.fromRGB(70, 70, 90);
ddStroke.Thickness = 1
local ddList = Instance.new("UIListLayout", dropdown);
ddList.Padding = UDim.new(0, 4)
Instance.new("UIPadding", dropdown).PaddingTop = UDim.new(0, 6);
Instance.new("UIPadding", dropdown).PaddingBottom = UDim.new(0, 6);
Instance.new("UIPadding", dropdown).PaddingLeft = UDim.new(0, 6);
Instance.new("UIPadding", dropdown).PaddingRight = UDim.new(0, 6)
local actionRow = Instance.new("Frame", main);
actionRow.Name = "ActionRow";
actionRow.Position = UDim2.fromOffset(10, 92);
actionRow.Size = UDim2.new(1, - 20, 0, 34);
actionRow.BackgroundTransparency = 1
local btnWarp = Instance.new("TextButton", actionRow);
btnWarp.Name = "WarpBtn";
btnWarp.Size = UDim2.new(0.5, - 4, 1, 0);
btnWarp.Position = UDim2.fromOffset(0, 0);
btnWarp.BackgroundColor3 = Color3.fromRGB(0, 170, 90);
btnWarp.Text = "Enter Vehicle";
btnWarp.Font = Enum.Font.GothamBold;
btnWarp.TextSize = 11;
btnWarp.TextColor3 = Color3.new(1, 1, 1);
Instance.new("UICorner", btnWarp).CornerRadius = UDim.new(0, 10)
local warpStroke = Instance.new("UIStroke", btnWarp);
warpStroke.Color = Color3.fromRGB(0, 220, 120);
warpStroke.Thickness = 1
local btnApply = Instance.new("TextButton", actionRow);
btnApply.Name = "ApplyBtn";
btnApply.Size = UDim2.new(0.5, - 4, 1, 0);
btnApply.Position = UDim2.new(0.5, 4, 0, 0);
btnApply.BackgroundColor3 = Color3.fromRGB(70, 90, 220);
btnApply.Text = "Apply Tune";
btnApply.Font = Enum.Font.GothamBold;
btnApply.TextSize = 11;
btnApply.TextColor3 = Color3.new(1, 1, 1);
Instance.new("UICorner", btnApply).CornerRadius = UDim.new(0, 10)
local applyStroke = Instance.new("UIStroke", btnApply);
applyStroke.Color = Color3.fromRGB(100, 120, 255);
applyStroke.Thickness = 1
local tabBar = Instance.new("Frame", main);
tabBar.Name = "TabBar";
tabBar.Position = UDim2.fromOffset(0, 132);
tabBar.Size = UDim2.new(1, 0, 0, 30);
tabBar.BackgroundColor3 = Color3.fromRGB(22, 22, 28);
tabBar.BorderSizePixel = 0
local tabLayout = Instance.new("UIListLayout", tabBar);
tabLayout.FillDirection = Enum.FillDirection.Horizontal;
tabLayout.Padding = UDim.new(0, 5);
tabLayout.HorizontalAlignment = Enum.HorizontalAlignment.Center;
tabLayout.VerticalAlignment = Enum.VerticalAlignment.Center
Instance.new("UIPadding", tabBar).PaddingLeft = UDim.new(0, 6)
local content = Instance.new("Frame", main);
content.Name = "Content";
content.Position = UDim2.fromOffset(0, 162);
content.Size = UDim2.new(1, 0, 1, - 172);
content.BackgroundTransparency = 1;
content.ClipsDescendants = true
local scroll = Instance.new("ScrollingFrame", content);
scroll.Name = "Scroll";
scroll.Size = UDim2.new(1, - 8, 1, 0);
scroll.Position = UDim2.fromOffset(4, 0);
scroll.BackgroundTransparency = 1;
scroll.BorderSizePixel = 0;
scroll.ScrollBarThickness = 4;
scroll.ScrollBarImageColor3 = Color3.fromRGB(90, 90, 100);
scroll.AutomaticCanvasSize = Enum.AutomaticSize.Y;
scroll.CanvasSize = UDim2.new(0, 0, 0, 0)
local list = Instance.new("UIListLayout", scroll);
list.Padding = UDim.new(0, 8);
list.SortOrder = Enum.SortOrder.LayoutOrder
Instance.new("UIPadding", scroll).PaddingTop = UDim.new(0, 6);
Instance.new("UIPadding", scroll).PaddingBottom = UDim.new(0, 12);
Instance.new("UIPadding", scroll).PaddingLeft = UDim.new(0, 6);
Instance.new("UIPadding", scroll).PaddingRight = UDim.new(0, 6)
local toast = Instance.new("TextLabel", main);
toast.Name = "Toast";
toast.Size = UDim2.new(1, - 20, 0, 26);
toast.Position = UDim2.new(0, 10, 1, - 30);
toast.BackgroundColor3 = Color3.fromRGB(40, 180, 80);
toast.Text = "Done";
toast.Font = Enum.Font.GothamBold;
toast.TextSize = 11;
toast.TextColor3 = Color3.new(1, 1, 1);
toast.Visible = false;
toast.ZIndex = 20;
Instance.new("UICorner", toast).CornerRadius = UDim.new(0, 8)
local function showToast(msg, col, dur)
	toast.Text = msg;
	toast.BackgroundColor3 = col or Color3.fromRGB(40, 180, 80);
	toast.Visible = true;
	task.delay(dur or 1.2, function()
		if toast and toast.Parent then
			toast.Visible = false
		end
	end)
end
local function fmt(v)
	if type(v) == "number" then
		if v % 1 == 0 then
			return tostring(math.floor(v))
		else
			return string.format("%.2f", v)
		end
	end
	return tostring(v)
end
local function captureLive()
	local t = {}
	for k, v in pairs(tuner) do
		if type(v) == "number" or type(v) == "boolean" then
			t[k] = v
		end
	end
	if tuner.Ratios then
		t["Ratios"] = {
			tuner.Ratios[1],
			tuner.Ratios[2],
			tuner.Ratios[3],
			tuner.Ratios[4],
			tuner.Ratios[5]
		}
	end
	saveGlobal(t)
	return t
end
local allCards = {}
local sliderCards = {}
local function addSlider(key, displayName, opts)
	opts = opts or {};
	local minV = opts.min or 0;
	local maxV = opts.max or 100;
	local step = opts.step or 1;
	local cat = opts.cat or "General";
	local desc = opts.desc or ""
	local card = Instance.new("Frame");
	card.Size = UDim2.new(1, - 6, 0, 62);
	card.BackgroundColor3 = Color3.fromRGB(29, 29, 38);
	card.BorderSizePixel = 0;
	card.Name = key;
	Instance.new("UICorner", card).CornerRadius = UDim.new(0, 10);
	local s = Instance.new("UIStroke", card);
	s.Color = Color3.fromRGB(44, 44, 54);
	s.Thickness = 1;
	card.Parent = scroll;
	card:SetAttribute("Category", cat);
	card:SetAttribute("Key", displayName:lower() .. " " .. key:lower());
	table.insert(allCards, card)
	local nameLbl = Instance.new("TextLabel", card);
	nameLbl.Position = UDim2.fromOffset(10, 6);
	nameLbl.Size = UDim2.new(1, - 130, 0, 15);
	nameLbl.BackgroundTransparency = 1;
	nameLbl.Text = displayName;
	nameLbl.Font = Enum.Font.GothamBold;
	nameLbl.TextSize = 12;
	nameLbl.TextColor3 = Color3.new(1, 1, 1);
	nameLbl.TextXAlignment = Enum.TextXAlignment.Left
	local typeLbl = Instance.new("TextLabel", card);
	typeLbl.Position = UDim2.fromOffset(10, 21);
	typeLbl.Size = UDim2.new(1, - 130, 0, 11);
	typeLbl.BackgroundTransparency = 1;
	typeLbl.Text = cat .. "  â€ĸ  " .. desc;
	typeLbl.Font = Enum.Font.Gotham;
	typeLbl.TextSize = 9;
	typeLbl.TextColor3 = Color3.fromRGB(135, 135, 145);
	typeLbl.TextXAlignment = Enum.TextXAlignment.Left
	local origLbl = Instance.new("TextLabel", card);
	origLbl.Position = UDim2.fromOffset(10, 32);
	origLbl.Size = UDim2.new(1, - 130, 0, 10);
	origLbl.BackgroundTransparency = 1;
	origLbl.Text = "Default: " .. fmt(defaults[key] or tuner[key]);
	origLbl.Font = Enum.Font.Gotham;
	origLbl.TextSize = 8;
	origLbl.TextColor3 = Color3.fromRGB(100, 100, 110);
	origLbl.TextXAlignment = Enum.TextXAlignment.Left
	local valLbl = Instance.new("TextLabel", card);
	valLbl.Size = UDim2.fromOffset(68, 20);
	valLbl.Position = UDim2.new(1, - 76, 0, 6);
	valLbl.BackgroundColor3 = Color3.fromRGB(40, 40, 50);
	valLbl.Text = fmt(tuner[key]);
	valLbl.Font = Enum.Font.GothamBold;
	valLbl.TextSize = 11;
	valLbl.TextColor3 = Color3.fromRGB(255, 220, 100);
	Instance.new("UICorner", valLbl).CornerRadius = UDim.new(0, 6)
	local sliderBG = Instance.new("Frame", card);
	sliderBG.Position = UDim2.new(1, - 128, 0, 38);
	sliderBG.Size = UDim2.new(0, 90, 0, 6);
	sliderBG.BackgroundColor3 = Color3.fromRGB(50, 50, 60);
	Instance.new("UICorner", sliderBG).CornerRadius = UDim.new(1, 0)
	local fill = Instance.new("Frame", sliderBG);
	fill.Size = UDim2.new(0.5, 0, 1, 0);
	fill.BackgroundColor3 = Color3.fromRGB(255, 70, 70);
	Instance.new("UICorner", fill).CornerRadius = UDim.new(1, 0)
	local knob = Instance.new("Frame", sliderBG);
	knob.Size = UDim2.fromOffset(12, 12);
	knob.Position = UDim2.new(0.5, - 6, 0.5, - 6);
	knob.BackgroundColor3 = Color3.new(1, 1, 1);
	Instance.new("UICorner", knob).CornerRadius = UDim.new(1, 0);
	knob.ZIndex = 2
	local minusBtn = Instance.new("TextButton", card);
	minusBtn.Size = UDim2.fromOffset(22, 22);
	minusBtn.Position = UDim2.new(1, - 158, 0, 30);
	minusBtn.Text = "−";
	minusBtn.Font = Enum.Font.GothamBold;
	minusBtn.TextSize = 14;
	minusBtn.TextColor3 = Color3.new(1, 1, 1);
	minusBtn.BackgroundColor3 = Color3.fromRGB(50, 50, 60);
	Instance.new("UICorner", minusBtn).CornerRadius = UDim.new(0, 6)
	local plusBtn = Instance.new("TextButton", card);
	plusBtn.Size = UDim2.fromOffset(22, 22);
	plusBtn.Position = UDim2.new(1, - 30, 0, 30);
	plusBtn.Text = "+";
	plusBtn.Font = Enum.Font.GothamBold;
	plusBtn.TextSize = 14;
	plusBtn.TextColor3 = Color3.new(1, 1, 1);
	plusBtn.BackgroundColor3 = Color3.fromRGB(50, 50, 60);
	Instance.new("UICorner", plusBtn).CornerRadius = UDim.new(0, 6)
	local origVal = defaults[key] or tuner[key]
	sliderCards[key] = {
		valLbl = valLbl,
		fill = fill,
		knob = knob,
		origVal = origVal,
		minV = minV,
		maxV = maxV
	}
	local function updateVisual(v)
		local pct = math.clamp((v - minV) / (maxV - minV), 0, 1);
		fill.Size = UDim2.new(pct, 0, 1, 0);
		knob.Position = UDim2.new(pct, - 6, 0.5, - 6);
		valLbl.Text = fmt(v);
		valLbl.TextColor3 = (v ~= origVal and Color3.fromRGB(100, 220, 255) or Color3.fromRGB(255, 220, 100))
	end
	updateVisual(tuner[key])
	local function setVal(newV)
		newV = math.clamp(newV, minV, maxV);
		newV = math.floor(newV / step + 0.5) * step;
		if maxV == 16000 then
			newV = math.floor(newV)
		end
		tuner[key] = newV;
		updateVisual(newV);
		captureLive()
	end
	local dragging = false;
	sliderBG.InputBegan:Connect(function(i)
		if i.UserInputType == Enum.UserInputType.MouseButton1 then
			dragging = true
		end
	end);
	knob.InputBegan:Connect(function(i)
		if i.UserInputType == Enum.UserInputType.MouseButton1 then
			dragging = true
		end
	end);
	game:GetService("UserInputService").InputEnded:Connect(function(i)
		if i.UserInputType == Enum.UserInputType.MouseButton1 then
			dragging = false
		end
	end);
	game:GetService("UserInputService").InputChanged:Connect(function(i)
		if dragging and i.UserInputType == Enum.UserInputType.MouseMovement then
			local rel = (i.Position.X - sliderBG.AbsolutePosition.X) / sliderBG.AbsoluteSize.X;
			setVal(minV + math.clamp(rel, 0, 1) * (maxV - minV))
		end
	end)
	minusBtn.MouseButton1Click:Connect(function()
		setVal(tuner[key] - step)
	end);
	plusBtn.MouseButton1Click:Connect(function()
		setVal(tuner[key] + step)
	end)
	return card
end
local function addToggle(key, displayName, cat, desc, onText, offText)
	onText = onText or "ON";
	offText = offText or "OFF"
	local card = Instance.new("Frame");
	card.Size = UDim2.new(1, - 6, 0, 52);
	card.BackgroundColor3 = Color3.fromRGB(29, 29, 38);
	card.Name = key;
	Instance.new("UICorner", card).CornerRadius = UDim.new(0, 10);
	local s = Instance.new("UIStroke", card);
	s.Color = Color3.fromRGB(44, 44, 54);
	s.Thickness = 1;
	card.Parent = scroll;
	card:SetAttribute("Category", cat);
	card:SetAttribute("Key", displayName:lower() .. " " .. key:lower());
	table.insert(allCards, card)
	local nameLbl = Instance.new("TextLabel", card);
	nameLbl.Position = UDim2.fromOffset(10, 8);
	nameLbl.Size = UDim2.new(1, - 110, 0, 15);
	nameLbl.BackgroundTransparency = 1;
	nameLbl.Text = displayName;
	nameLbl.Font = Enum.Font.GothamBold;
	nameLbl.TextSize = 12;
	nameLbl.TextColor3 = Color3.new(1, 1, 1);
	nameLbl.TextXAlignment = Enum.TextXAlignment.Left
	local typeLbl = Instance.new("TextLabel", card);
	typeLbl.Position = UDim2.fromOffset(10, 24);
	typeLbl.Size = UDim2.new(1, - 110, 0, 11);
	typeLbl.BackgroundTransparency = 1;
	typeLbl.Text = cat .. "  â€ĸ  " .. desc;
	typeLbl.Font = Enum.Font.Gotham;
	typeLbl.TextSize = 9;
	typeLbl.TextColor3 = Color3.fromRGB(135, 135, 145);
	typeLbl.TextXAlignment = Enum.TextXAlignment.Left
	local isOn = type(tuner[key]) == "number" and tuner[key] >= 1 or tuner[key] == true
	local tog = Instance.new("TextButton", card);
	tog.Size = UDim2.fromOffset(72, 28);
	tog.Position = UDim2.new(1, - 82, 0, 12);
	tog.BackgroundColor3 = isOn and Color3.fromRGB(0, 200, 100) or Color3.fromRGB(60, 60, 70);
	tog.Text = isOn and onText or offText;
	tog.Font = Enum.Font.GothamBold;
	tog.TextSize = 10;
	tog.TextColor3 = Color3.new(1, 1, 1);
	tog.AutoButtonColor = false;
	Instance.new("UICorner", tog).CornerRadius = UDim.new(0, 14)
	local knob = Instance.new("Frame", tog);
	knob.Size = UDim2.fromOffset(22, 22);
	knob.Position = isOn and UDim2.fromOffset(47, 3) or UDim2.fromOffset(3, 3);
	knob.BackgroundColor3 = Color3.new(1, 1, 1);
	Instance.new("UICorner", knob).CornerRadius = UDim.new(1, 0)
	tog.MouseButton1Click:Connect(function()
		local curIsOn = type(tuner[key]) == "number" and tuner[key] >= 1 or tuner[key] == true
		local newVal = type(tuner[key]) == "number" and (curIsOn and 0 or 1) or not curIsOn
		tuner[key] = newVal
		local on = type(newVal) == "number" and newVal >= 1 or newVal == true
		tog.Text = on and onText or offText;
		tog.BackgroundColor3 = on and Color3.fromRGB(0, 200, 100) or Color3.fromRGB(60, 60, 70);
		knob.Position = on and UDim2.fromOffset(47, 3) or UDim2.fromOffset(3, 3)
		captureLive()
	end)
	return card
end
addSlider("Redline", "Rev Limit", {
	min = 4000,
	max = 16000,
	step = 250,
	cat = "Engine",
	desc = "Max RPM before limiter"
})
addSlider("E_Redline", "Secondary Rev Limit", {
	min = 4000,
	max = 16000,
	step = 250,
	cat = "Engine",
	desc = "Secondary limiter"
})
addSlider("PeakRPM", "Peak Power RPM", {
	min = 3000,
	max = 16000,
	step = 250,
	cat = "Engine",
	desc = "RPM at peak power"
})
addSlider("IdleRPM", "Idle RPM", {
	min = 500,
	max = 3000,
	step = 50,
	cat = "Engine",
	desc = "Idle speed"
})
addSlider("Horsepower", "Horsepower", {
	min = 20,
	max = 1200,
	step = 10,
	cat = "Engine",
	desc = "Engine output"
})
addSlider("E_Horsepower", "Extra Horsepower", {
	min = 50,
	max = 1200,
	step = 10,
	cat = "Engine",
	desc = "Secondary output"
})
addSlider("RevAccel", "Throttle Response", {
	min = 50,
	max = 600,
	step = 10,
	cat = "Engine",
	desc = "Engine responsiveness"
})
addToggle("Turbochargers", "Turbocharger", "Forced Induction", "Turbo system", "Installed", "Not Installed")
addToggle("Superchargers", "Supercharger", "Forced Induction", "Supercharger system", "Installed", "Not Installed")
addSlider("T_Boost", "Turbo Boost", {
	min = 0,
	max = 40,
	step = 1,
	cat = "Forced Induction",
	desc = "Turbo boost pressure"
})
addSlider("S_Boost", "Supercharger Boost", {
	min = 0,
	max = 40,
	step = 1,
	cat = "Forced Induction",
	desc = "Supercharger boost"
})
addSlider("Weight", "Vehicle Weight", {
	min = 100,
	max = 3000,
	step = 20,
	cat = "Weight",
	desc = "Total mass (kg)"
})
addSlider("WeightDistribution", "Weight Balance", {
	min = 20,
	max = 80,
	step = 1,
	cat = "Weight",
	desc = "Front weight %"
})
addSlider("CGHeight", "Center of Gravity", {
	min = 0,
	max = 3,
	step = 0.05,
	cat = "Weight",
	desc = "CG height"
})
addSlider("FinalDrive", "Final Drive", {
	min = 1,
	max = 8,
	step = 0.1,
	cat = "Transmission",
	desc = "Final drive ratio"
})
addSlider("ShiftUpTime", "Upshift Time", {
	min = 0,
	max = 1,
	step = 0.05,
	cat = "Transmission",
	desc = "Upshift duration (s)"
})
addSlider("ShiftDnTime", "Downshift Time", {
	min = 0,
	max = 1,
	step = 0.05,
	cat = "Transmission",
	desc = "Downshift duration (s)"
})
do
	local card = Instance.new("Frame", scroll);
	card.Size = UDim2.new(1, - 6, 0, 88);
	card.BackgroundColor3 = Color3.fromRGB(29, 29, 38);
	card.Name = "Ratios";
	card:SetAttribute("Category", "Transmission");
	card:SetAttribute("Key", "gear ratios");
	Instance.new("UICorner", card).CornerRadius = UDim.new(0, 10);
	local s = Instance.new("UIStroke", card);
	s.Color = Color3.fromRGB(44, 44, 54);
	local lbl = Instance.new("TextLabel", card);
	lbl.Position = UDim2.fromOffset(10, 6);
	lbl.Size = UDim2.new(1, - 20, 0, 14);
	lbl.BackgroundTransparency = 1;
	lbl.Text = "Gear Ratios  (1 - 5)";
	lbl.Font = Enum.Font.GothamBold;
	lbl.TextSize = 12;
	lbl.TextColor3 = Color3.new(1, 1, 1);
	lbl.TextXAlignment = Enum.TextXAlignment.Left;
	local sub2 = Instance.new("TextLabel", card);
	sub2.Position = UDim2.fromOffset(10, 20);
	sub2.Size = UDim2.new(1, - 20, 0, 11);
	sub2.BackgroundTransparency = 1;
	sub2.Text = "Transmission  â€ĸ  Individual gear ratios";
	sub2.Font = Enum.Font.Gotham;
	sub2.TextSize = 9;
	sub2.TextColor3 = Color3.fromRGB(135, 135, 145);
	sub2.TextXAlignment = Enum.TextXAlignment.Left;
	local row = Instance.new("Frame", card);
	row.Position = UDim2.fromOffset(6, 36);
	row.Size = UDim2.new(1, - 12, 0, 44);
	row.BackgroundTransparency = 1;
	local l = Instance.new("UIListLayout", row);
	l.FillDirection = Enum.FillDirection.Horizontal;
	l.Padding = UDim.new(0, 6);
	l.HorizontalAlignment = Enum.HorizontalAlignment.Center;
	for i = 1, 5 do
		local col = Instance.new("Frame", row);
		col.Size = UDim2.fromOffset(80, 44);
		col.BackgroundColor3 = Color3.fromRGB(40, 40, 50);
		Instance.new("UICorner", col).CornerRadius = UDim.new(0, 8);
		local gl = Instance.new("TextLabel", col);
		gl.Size = UDim2.new(1, 0, 0, 14);
		gl.BackgroundTransparency = 1;
		gl.Text = "Gear " .. i;
		gl.Font = Enum.Font.GothamBold;
		gl.TextSize = 10;
		gl.TextColor3 = Color3.fromRGB(160, 160, 170);
		local box = Instance.new("TextBox", col);
		box.Position = UDim2.fromOffset(4, 16);
		box.Size = UDim2.new(1, - 8, 0, 22);
		box.Text = tostring(tuner.Ratios[i] or 0);
		box.Font = Enum.Font.GothamBold;
		box.TextSize = 12;
		box.TextColor3 = Color3.fromRGB(255, 220, 100);
		box.BackgroundColor3 = Color3.fromRGB(36, 36, 44);
		box.ClearTextOnFocus = false;
		Instance.new("UICorner", box).CornerRadius = UDim.new(0, 6);
		box.FocusLost:Connect(function(enter)
			if enter then
				local n = tonumber(box.Text);
				if n then
					tuner.Ratios[i] = n;
					captureLive()
				end
			end
		end)
	end;
	table.insert(allCards, card)
end
addToggle("ABS", "ABS", "Brakes", "Anti-lock Braking System", "Enabled", "Disabled")
addSlider("ABSThreshold", "ABS Threshold", {
	min = 0,
	max = 100,
	step = 2,
	cat = "Brakes",
	desc = "ABS activation point"
})
addToggle("TCS", "Traction Control", "Brakes", "Traction Control System", "Enabled", "Disabled")
addSlider("TCSThreshold", "TCS Threshold", {
	min = 0,
	max = 100,
	step = 2,
	cat = "Brakes",
	desc = "TCS activation point"
})
addSlider("BrakesRatio", "Brake Balance", {
	min = 0,
	max = 100,
	step = 2,
	cat = "Brakes",
	desc = "Front brake bias %"
})
addSlider("FBrakeForce", "Front Brake Force", {
	min = 0,
	max = 5000,
	step = 50,
	cat = "Brakes",
	desc = "Front braking force"
})
addSlider("RBrakeForce", "Rear Brake Force", {
	min = 0,
	max = 5000,
	step = 50,
	cat = "Brakes",
	desc = "Rear braking force"
})
addSlider("SpeedLimit", "Top Speed Limit", {
	min = 50,
	max = 600,
	step = 10,
	cat = "Useful",
	desc = "Maximum speed (km/h)"
})
addSlider("SteerAngle", "Steering Angle", {
	min = 5,
	max = 50,
	step = 1,
	cat = "Useful",
	desc = "Max steering angle"
})
addSlider("FTireFriction", "Front Grip", {
	min = 0.2,
	max = 3,
	step = 0.05,
	cat = "Useful",
	desc = "Front tire grip"
})
addSlider("RTireFriction", "Rear Grip", {
	min = 0.2,
	max = 3,
	step = 0.05,
	cat = "Useful",
	desc = "Rear tire grip"
})
addSlider("Drag", "Aerodynamic Drag", {
	min = 0,
	max = 2,
	step = 0.05,
	cat = "Useful",
	desc = "Air resistance"
})
local configCard = Instance.new("Frame", scroll);
configCard.Size = UDim2.new(1, - 6, 0, 110);
configCard.BackgroundColor3 = Color3.fromRGB(34, 34, 48);
configCard.Name = "__CONFIG__";
configCard:SetAttribute("Category", "Config");
configCard:SetAttribute("Key", "preset config");
Instance.new("UICorner", configCard).CornerRadius = UDim.new(0, 10);
local sc = Instance.new("UIStroke", configCard);
sc.Color = Color3.fromRGB(90, 90, 180);
sc.Thickness = 1.2;
local cTitle = Instance.new("TextLabel", configCard);
cTitle.Position = UDim2.fromOffset(10, 8);
cTitle.Size = UDim2.new(1, - 20, 0, 16);
cTitle.BackgroundTransparency = 1;
cTitle.Text = "Presets  â€ĸ  Save / Load";
cTitle.Font = Enum.Font.GothamBold;
cTitle.TextSize = 12;
cTitle.TextColor3 = Color3.fromRGB(160, 180, 255);
cTitle.TextXAlignment = Enum.TextXAlignment.Left;
local cDesc = Instance.new("TextLabel", configCard);
cDesc.Position = UDim2.fromOffset(10, 24);
cDesc.Size = UDim2.new(1, - 20, 0, 10);
cDesc.BackgroundTransparency = 1;
cDesc.Text = "Save current setup for later use";
cDesc.Font = Enum.Font.Gotham;
cDesc.TextSize = 9;
cDesc.TextColor3 = Color3.fromRGB(130, 130, 150);
cDesc.TextXAlignment = Enum.TextXAlignment.Left;
local btnSave = Instance.new("TextButton", configCard);
btnSave.Position = UDim2.fromOffset(8, 42);
btnSave.Size = UDim2.new(0.5, - 12, 0, 28);
btnSave.Text = "Save Preset";
btnSave.Font = Enum.Font.GothamBold;
btnSave.TextSize = 11;
btnSave.TextColor3 = Color3.new(1, 1, 1);
btnSave.BackgroundColor3 = Color3.fromRGB(70, 90, 220);
Instance.new("UICorner", btnSave).CornerRadius = UDim.new(0, 8);
local btnLoad = Instance.new("TextButton", configCard);
btnLoad.Position = UDim2.new(0.5, 4, 0, 42);
btnLoad.Size = UDim2.new(0.5, - 12, 0, 28);
btnLoad.Text = "Load Preset";
btnLoad.Font = Enum.Font.GothamBold;
btnLoad.TextSize = 11;
btnLoad.TextColor3 = Color3.new(1, 1, 1);
btnLoad.BackgroundColor3 = Color3.fromRGB(50, 50, 60);
Instance.new("UICorner", btnLoad).CornerRadius = UDim.new(0, 8);
local btnReset = Instance.new("TextButton", configCard);
btnReset.Position = UDim2.fromOffset(8, 74);
btnReset.Size = UDim2.new(1, - 16, 0, 28);
btnReset.Text = "Restore Defaults";
btnReset.Font = Enum.Font.GothamBold;
btnReset.TextSize = 11;
btnReset.TextColor3 = Color3.new(1, 1, 1);
btnReset.BackgroundColor3 = Color3.fromRGB(180, 50, 50);
Instance.new("UICorner", btnReset).CornerRadius = UDim.new(0, 8);
table.insert(allCards, configCard)
local _preset = nil
btnSave.MouseButton1Click:Connect(function()
	_preset = {};
	for k, v in pairs(tuner) do
		if type(v) == "number" or type(v) == "boolean" then
			_preset[k] = v
		end
	end;
	if tuner.Ratios then
		_preset["Ratios"] = {
			tuner.Ratios[1],
			tuner.Ratios[2],
			tuner.Ratios[3],
			tuner.Ratios[4],
			tuner.Ratios[5]
		}
	end;
	saveGlobal(_preset);
	btnSave.Text = "Saved!";
	showToast("Preset saved to _G", Color3.fromRGB(70, 90, 220));
	task.wait(0.8);
	btnSave.Text = "Save Preset"
end)
btnLoad.MouseButton1Click:Connect(function()
	local src = _preset or loadGlobal()
	if not src then
		showToast("No preset saved", Color3.fromRGB(180, 50, 50));
		return
	end
	for k, v in pairs(src) do
		if k == "Ratios" then
			for i = 1, 5 do
				tuner.Ratios[i] = v[i]
			end
		elseif tuner[k] ~= nil then
			tuner[k] = v
		end
	end
	for key, info in pairs(sliderCards) do
		if tuner[key] ~= nil then
			local v = tuner[key];
			local pct = math.clamp((v - info.minV) / (info.maxV - info.minV), 0, 1);
			info.fill.Size = UDim2.new(pct, 0, 1, 0);
			info.knob.Position = UDim2.new(pct, - 6, 0.5, - 6);
			info.valLbl.Text = fmt(v)
		end
	end
	saveGlobal(src);
	showToast("Preset loaded", Color3.fromRGB(50, 180, 90))
end)
btnReset.MouseButton1Click:Connect(function()
	for k, v in pairs(defaults) do
		if k == "Ratios" then
			for i = 1, 5 do
				tuner.Ratios[i] = v[i]
			end
		elseif tuner[k] ~= nil then
			tuner[k] = v
		end
	end
	for key, info in pairs(sliderCards) do
		if tuner[key] ~= nil then
			local v = tuner[key];
			local pct = math.clamp((v - info.minV) / (info.maxV - info.minV), 0, 1);
			info.fill.Size = UDim2.new(pct, 0, 1, 0);
			info.knob.Position = UDim2.new(pct, - 6, 0.5, - 6);
			info.valLbl.Text = fmt(v)
		end
	end
	captureLive();
	showToast("Restored defaults", Color3.fromRGB(180, 50, 50))
end)

-- Tabs
local tabNames = {
	"All",
	"Engine",
	"Forced Induction",
	"Weight",
	"Transmission",
	"Brakes",
	"Useful",
	"Config"
}
local catKeys = {
	"All",
	"Engine",
	"Forced Induction",
	"Weight",
	"Transmission",
	"Brakes",
	"Useful",
	"Config"
}
local activeTab = "All"
local function filter()
	for _, card in ipairs(allCards) do
		local cat = card:GetAttribute("Category");
		card.Visible = (activeTab == "All" or cat == activeTab)
	end
end
for i, name in ipairs(tabNames) do
	local catKey = catKeys[i];
	local b = Instance.new("TextButton");
	b.Size = UDim2.fromOffset(0, 26);
	b.AutomaticSize = Enum.AutomaticSize.X;
	b.Text = " " .. name .. " ";
	b.Font = Enum.Font.GothamBold;
	b.TextSize = 10;
	b.TextColor3 = (catKey == activeTab and Color3.new(1, 1, 1) or Color3.fromRGB(170, 170, 180));
	b.BackgroundColor3 = (catKey == activeTab and Color3.fromRGB(255, 70, 70) or Color3.fromRGB(36, 36, 44));
	b.AutoButtonColor = false;
	Instance.new("UICorner", b).CornerRadius = UDim.new(0, 8);
	b.Parent = tabBar;
	b.MouseButton1Click:Connect(function()
		activeTab = catKey;
		for _, ch in ipairs(tabBar:GetChildren()) do
			if ch:IsA("TextButton") then
				ch.BackgroundColor3 = Color3.fromRGB(36, 36, 44);
				ch.TextColor3 = Color3.fromRGB(170, 170, 180)
			end
		end;
		b.BackgroundColor3 = Color3.fromRGB(255, 70, 70);
		b.TextColor3 = Color3.new(1, 1, 1);
		filter()
	end)
end
local UIS = game:GetService("UserInputService");
local dragging, dragStart, startPos;
top.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		dragging = true;
		dragStart = input.Position;
		startPos = main.Position
	end
end);
UIS.InputChanged:Connect(function(input)
	if dragging and input.UserInputType == Enum.UserInputType.MouseMovement then
		local delta = input.Position - dragStart;
		main.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
	end
end);
UIS.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		dragging = false
	end
end)
local minimized = false;
local fullSize = main.Size;
local miniSize = UDim2.fromOffset(500, 50)
btnMin.MouseButton1Click:Connect(function()
	minimized = not minimized;
	if minimized then
		main.Size = miniSize;
		btnMin.Text = "□";
		content.Visible = false;
		actionRow.Visible = false;
		carRow.Visible = false
	else
		main.Size = fullSize;
		btnMin.Text = "—";
		content.Visible = true;
		actionRow.Visible = true;
		carRow.Visible = true
	end
end)
btnClose.MouseButton1Click:Connect(function()
	gui:Destroy()
end)
local function rebuildDropdown()
	for _, c in ipairs(dropdown:GetChildren()) do
		if c:IsA("TextButton") then
			c:Destroy()
		end
	end
	local cars = findAllCars()
	for _, car in ipairs(cars) do
		local b = Instance.new("TextButton", dropdown);
		b.Size = UDim2.new(1, - 6, 0, 28);
		b.BackgroundColor3 = (car == currentCar and Color3.fromRGB(255, 70, 70) or Color3.fromRGB(36, 36, 44));
		b.Text = "  " .. car.Name .. (car == currentCar and "  ✓" or "");
		b.Font = Enum.Font.Gotham;
		b.TextSize = 11;
		b.TextColor3 = Color3.new(1, 1, 1);
		b.TextXAlignment = Enum.TextXAlignment.Left;
		Instance.new("UICorner", b).CornerRadius = UDim.new(0, 6)
		if car.Name:lower():find(LocalPlayer.Name:lower(), 1, true) then
			b.BackgroundColor3 = (car == currentCar and Color3.fromRGB(0, 170, 90) or Color3.fromRGB(40, 80, 60));
			b.Text = "  ★ " .. car.Name .. (car == currentCar and "  ✓" or "")
		end
		b.MouseButton1Click:Connect(function()
			captureLive()
			currentCar = car;
			tuner = getTuner(car);
			workspace:SetAttribute("TunerLastCar", car.Name)
			local s = loadGlobal()
			if s then
				for k, v in pairs(s) do
					if k == "Ratios" and tuner.Ratios then
						for i = 1, 5 do
							if v[i] ~= nil then
								tuner.Ratios[i] = v[i]
							end
						end
					elseif tuner[k] ~= nil then
						tuner[k] = v
					end
				end
			end
			carLabel.Text = "🚗 " .. car.Name;
			carLabel.TextColor3 = Color3.fromRGB(100, 220, 255)
			dropdown.Visible = false;
			btnPick.Text = "Select"
			for key, info in pairs(sliderCards) do
				if tuner[key] ~= nil then
					local v = tuner[key];
					local pct = math.clamp((v - info.minV) / (info.maxV - info.minV), 0, 1);
					info.fill.Size = UDim2.new(pct, 0, 1, 0);
					info.knob.Position = UDim2.new(pct, - 6, 0.5, - 6);
					info.valLbl.Text = fmt(v)
				end
			end
			showToast("Switched & applied tune to " .. car.Name, Color3.fromRGB(70, 90, 220), 1.2)
		end)
	end
end
rebuildDropdown()
btnPick.MouseButton1Click:Connect(function()
	dropdown.Visible = not dropdown.Visible;
	btnPick.Text = dropdown.Visible and "Close" or "Select";
	if dropdown.Visible then
		rebuildDropdown()
	end
end)
btnRefresh.MouseButton1Click:Connect(function()
	rebuildDropdown()
	if currentCar and currentCar.Parent and currentCar:FindFirstChild("Tuner") then
		showToast("Refreshed", Color3.fromRGB(60, 140, 255), 1)
	else
		local nc = getPreferredCar()
		if nc then
			currentCar = nc;
			tuner = getTuner(nc)
			local s = loadGlobal()
			if s then
				for k, v in pairs(s) do
					if k == "Ratios" and tuner.Ratios then
						for i = 1, 5 do
							if v[i] ~= nil then
								tuner.Ratios[i] = v[i]
							end
						end
					elseif tuner[k] ~= nil then
						tuner[k] = v
					end
				end
			end
			carLabel.Text = "🚗 " .. nc.Name .. (s and " ✓ restored" or "");
			carLabel.TextColor3 = s and Color3.fromRGB(0, 220, 120) or Color3.fromRGB(100, 220, 255)
			for key, info in pairs(sliderCards) do
				if tuner[key] ~= nil then
					local v = tuner[key];
					local pct = math.clamp((v - info.minV) / (info.maxV - info.minV), 0, 1);
					info.fill.Size = UDim2.new(pct, 0, 1, 0);
					info.knob.Position = UDim2.new(pct, - 6, 0.5, - 6);
					info.valLbl.Text = fmt(v)
				end
			end
			showToast("Switched to " .. nc.Name, Color3.fromRGB(0, 180, 90), 1)
		else
			showToast("No vehicle found", Color3.fromRGB(180, 50, 50), 1)
		end
	end
end)
btnWarp.MouseButton1Click:Connect(function()
	local car = currentCar
	if not car or not car.Parent then
		car = getPreferredCar();
		if car then
			currentCar = car;
			tuner = getTuner(car);
			carLabel.Text = "🚗 " .. car.Name
		end
	end
	if not car or not car.Parent then
		showToast("No vehicle found", Color3.fromRGB(180, 50, 50), 1);
		return
	end
	local char = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
	local hrp = char:WaitForChild("HumanoidRootPart")
	local seat = car:FindFirstChild("DriveSeat")
	if not seat then
		showToast("No seat", Color3.fromRGB(180, 50, 50), 1);
		return
	end
	hrp.CFrame = seat.CFrame * CFrame.new(0, 3, 0);
	task.wait(0.1);
	local hum = char:FindFirstChildOfClass("Humanoid");
	if hum then
		seat:Sit(hum)
	end
end)
btnApply.MouseButton1Click:Connect(function()
	captureLive()
	local toApply = loadGlobal()
	if not toApply or next(toApply) == nil then
		showToast("No tune to apply", Color3.fromRGB(180, 50, 50), 1);
		return
	end
	local car = currentCar
	if not car or not car.Parent or not car:FindFirstChild("Tuner") then
		car = getPreferredCar();
		if car then
			currentCar = car;
			carLabel.Text = "🚗 " .. car.Name
		else
			showToast("No vehicle", Color3.fromRGB(180, 50, 50), 1);
			return
		end
	end
	local targetTuner = getTuner(car)
	if not targetTuner then
		showToast("Cannot access tuner", Color3.fromRGB(180, 50, 50), 1);
		return
	end
	local char = LocalPlayer.Character
	local hum = char and char:FindFirstChildOfClass("Humanoid")
	local hrp = char and char:FindFirstChild("HumanoidRootPart")
	local wasSeated = hum and hum.SeatPart ~= nil
	local prevSeat = hum and hum.SeatPart
	local targetSeat = car:FindFirstChild("DriveSeat")
	btnApply.Text = "Applying..."
	if wasSeated and hum and hrp then
		hum.Sit = false;
		if prevSeat then
			pcall(function()
				prevSeat.Disabled = true
			end)
		end;
		hum.Jump = true;
		pcall(function()
			hum:ChangeState(Enum.HumanoidStateType.Jumping)
		end)
		local t0 = tick();
		repeat
			task.wait(0.03);
			if hum.SeatPart == nil then
				break
			end;
			hum.Jump = true
		until tick() - t0 > 0.4
		if prevSeat then
			pcall(function()
				prevSeat.Disabled = false
			end)
		end;
		task.wait(0.06)
	end
	local count = 0
	for k, v in pairs(toApply) do
		if k == "Ratios" and type(v) == "table" and targetTuner.Ratios then
			for i = 1, 5 do
				if v[i] ~= nil then
					targetTuner.Ratios[i] = v[i];
					count += 1
				end
			end
		elseif targetTuner[k] ~= nil then
			targetTuner[k] = v;
			count += 1
		end
	end
	tuner = targetTuner
	if wasSeated and hum and targetSeat and hum.Parent then
		if hrp and targetSeat then
			hrp.CFrame = targetSeat.CFrame * CFrame.new(0, 2, 0)
		end;
		task.wait(0.06);
		pcall(function()
			targetSeat:Sit(hum)
		end)
	end
	btnApply.Text = "Apply Tune"
	showToast("Applied " .. count .. " values to " .. car.Name, Color3.fromRGB(0, 170, 90), 1.2)
end)
local lastNotify = 0
workspace.ChildAdded:Connect(function(obj)
	task.wait(0.4)
	if not obj:FindFirstChild("Tuner") or not obj:FindFirstChild("DriveSeat") then
		return
	end
	rebuildDropdown()
	local isMine = obj.Name:lower():find(LocalPlayer.Name:lower(), 1, true) ~= nil
	if not isMine then
		return
	end
	if tick() - lastNotify < 3 then
		return
	end
	lastNotify = tick()
	local s = loadGlobal()
	if s and next(s) ~= nil then
		local t = getTuner(obj)
		if t then
			for k, v in pairs(s) do
				if k == "Ratios" and t.Ratios then
					for i = 1, 5 do
						if v[i] ~= nil then
							t.Ratios[i] = v[i]
						end
					end
				elseif t[k] ~= nil then
					t[k] = v
				end
			end
		end
		if not currentCar or not currentCar.Parent then
			currentCar = obj;
			tuner = t or getTuner(obj);
			carLabel.Text = "🚗 " .. obj.Name .. " ✓ auto-applied";
			carLabel.TextColor3 = Color3.fromRGB(0, 220, 120)
			for key, info in pairs(sliderCards) do
				if tuner[key] ~= nil then
					local v = tuner[key];
					local pct = math.clamp((v - info.minV) / (info.maxV - info.minV), 0, 1);
					info.fill.Size = UDim2.new(pct, 0, 1, 0);
					info.knob.Position = UDim2.new(pct, - 6, 0.5, - 6);
					info.valLbl.Text = fmt(v)
				end
			end
		end
		showToast("New vehicle — tune auto-applied to " .. obj.Name, Color3.fromRGB(0, 170, 90), 2)
	else
		showToast("New vehicle: " .. obj.Name, Color3.fromRGB(70, 90, 220), 1.2)
	end
end)
workspace.ChildRemoved:Connect(function(obj)
	if obj == currentCar then
		carLabel.Text = "Vehicle removed — select another";
		carLabel.TextColor3 = Color3.fromRGB(255, 80, 80)
	end;
	task.wait(0.3);
	rebuildDropdown()
end)
print("Tuner v3.6 loaded — Vehicle: " .. currentCar.Name)

Features & Information

yay

Community Comments (0)

No comments yet for this script.