script.Parent.Parent:WaitForChild("\067\111\110\116\114\111\108\115")script.Parent.Parent:WaitForChild("\067\111\110\116\114\111\108\115\079\112\101\110")script.Parent:WaitForChild("\087\105\110\100\111\119")script.Parent:WaitForChild("\084\111\103\103\108\101")local R=script.Parent.Parent.Car.Value local x=require(R["\065-\067\104\097\115\115\105\115 \084\117\110\101"])local K=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local I=script.Parent local t=script.Parent.Parent.Controls local U=require(R["\065-\067\104\097\115\115\105\115 \084\117\110\101"].README)I.Window["\047\047\073\078\083\080\065\082\069"].Text="\065-\067\104\097\115\115\105\115 "..(U.." \098\121 \047\047\073\078\083\080\065\082\069")local d=false local A=nil local h=nil local F=false for R,x in pairs(x.Controls)do script.Parent.Parent.Controls:WaitForChild(R)local K=I.Window.Content[R]K.Text=x.Name K.MouseButton1Click:connect(function()script.Parent.Parent.ControlsOpen.Value=true I.Window.Overlay.Visible=true F=true repeat wait()until A~=nil if A==Enum.KeyCode.Return or A==Enum.KeyCode.KeypadEnter then elseif string.find(R,"\067\111\110\116\108\114")~=nil then if h.Name:find("\071\097\109\101\112\097\100")then t[R].Value=A.Name K.Text=A.Name else I.Window.Error.Visible=true end elseif R=="\077\111\117\115\101\084\104\114\111\116\116\108\101"or R=="\077\111\117\115\101\066\114\097\107\101"then if h==Enum.UserInputType.MouseButton1 or h==Enum.UserInputType.MouseButton2 then t[R].Value=h.Name K.Text=h.Name else I.Window.Error.Visible=true end else if h==Enum.UserInputType.Keyboard then t[R].Value=A.Name K.Text=A.Name else I.Window.Error.Visible=true end end A=nil h=nil F=false wait(.2)I.Window.Overlay.Visible=false script.Parent.Parent.ControlsOpen.Value=false end)end I.Window.Error.Changed:connect(function(R)if R=="\086\105\115\105\098\108\101"then wait(3)I.Window.Error.Visible=false end end)K.InputBegan:connect(function(R)if F then A=R.KeyCode h=R.UserInputType end end)K.InputChanged:connect(function(R)if F and(R.KeyCode==Enum.KeyCode.Thumbstick1 or R.KeyCode==Enum.KeyCode.Thumbstick2)then A=R.KeyCode h=R.UserInputType end end)I.Toggle.MouseButton1Click:connect(function()d=not d if d then I.Toggle.BackgroundColor3=Color3.new(1,.33333333333333,.5)I.Window:TweenPosition(UDim2.new(.5,-250,.5,-250),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.7,true)else I.Toggle.BackgroundColor3=Color3.new(1,.66666666666667,0)I.Window:TweenPosition(UDim2.new(.5,-250,0,-500),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.7,true)end end)I.Window.Tabs.Keyboard.MouseButton1Click:connect(function()I.Window.Content:TweenPosition(UDim2.new(0,0,0,60),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.4,true)I.Window.Tabs.Keyboard:TweenPosition(UDim2.new(0,5,0,0),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.4,true)I.Window.Tabs.Mouse:TweenPosition(UDim2.new(0,120,0,-5),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.4,true)I.Window.Tabs.Controller:TweenPosition(UDim2.new(0,235,0,-5),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.4,true)end)I.Window.Tabs.Mouse.MouseButton1Click:connect(function()I.Window.Content:TweenPosition(UDim2.new(-1,0,0,60),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.4,true)I.Window.Tabs.Keyboard:TweenPosition(UDim2.new(0,5,0,-5),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.4,true)I.Window.Tabs.Mouse:TweenPosition(UDim2.new(0,120,0,0),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.4,true)I.Window.Tabs.Controller:TweenPosition(UDim2.new(0,235,0,-5),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.4,true)end)I.Window.Tabs.Controller.MouseButton1Click:connect(function()I.Window.Content:TweenPosition(UDim2.new(-2,0,0,60),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.4,true)I.Window.Tabs.Keyboard:TweenPosition(UDim2.new(0,5,0,-5),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.4,true)I.Window.Tabs.Mouse:TweenPosition(UDim2.new(0,120,0,-5),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.4,true)I.Window.Tabs.Controller:TweenPosition(UDim2.new(0,235,0,0),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.4,true)end)wait(.5)I.Toggle:TweenPosition(UDim2.new(0,50,1,-30),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.4,false)for R=1,6,1 do I.Toggle.BackgroundColor3=Color3.new(.3921568627451,.3921568627451,.3921568627451)wait(.2)if d then I.Toggle.BackgroundColor3=Color3.new(1,.33333333333333,.5)else I.Toggle.BackgroundColor3=Color3.new(1,.66666666666667,0)end wait(.2)end
---Controls UI
script.Parent.Parent:WaitForChild("Controls")
script.Parent.Parent:WaitForChild("ControlsOpen")
script.Parent:WaitForChild("Window")
script.Parent:WaitForChild("Toggle")

local car = script.Parent.Parent.Car.Value
local _Tune = require(car["A-Chassis Tune"])
local UserInputService = game:GetService("UserInputService")
local cPanel = script.Parent
local Controls = script.Parent.Parent.Controls

local ver = require(car["A-Chassis Tune"].README)
cPanel.Window["//INSPARE"].Text = "A-Chassis " .. ver .. " by //INSPARE"

local controlsOpen = false
local cInputB = nil
local cInputT = nil
local cInput = false
for i, v in pairs(_Tune.Controls) do
	script.Parent.Parent.Controls:WaitForChild(i)
	local button = cPanel.Window.Content[i]
	button.Text = v.Name
	button.MouseButton1Click:connect(function()
		script.Parent.Parent.ControlsOpen.Value = true
		cPanel.Window.Overlay.Visible = true
		cInput = true
		repeat
			wait()
		until cInputB ~= nil
		if cInputB == Enum.KeyCode.Return or cInputB == Enum.KeyCode.KeypadEnter then
			--do nothing
		elseif string.find(i, "Contlr") ~= nil then
			if cInputT.Name:find("Gamepad") then
				Controls[i].Value = cInputB.Name
				button.Text = cInputB.Name
			else
				cPanel.Window.Error.Visible = true
			end
		elseif i == "MouseThrottle" or i == "MouseBrake" then
			if cInputT == Enum.UserInputType.MouseButton1 or cInputT == Enum.UserInputType.MouseButton2 then
				Controls[i].Value = cInputT.Name
				button.Text = cInputT.Name
			else
				cPanel.Window.Error.Visible = true
			end
		else
			if cInputT == Enum.UserInputType.Keyboard then
				Controls[i].Value = cInputB.Name
				button.Text = cInputB.Name
			else
				cPanel.Window.Error.Visible = true
			end
		end
		cInputB = nil
		cInputT = nil
		cInput = false
		wait(0.2)
		cPanel.Window.Overlay.Visible = false
		script.Parent.Parent.ControlsOpen.Value = false
	end)
end

cPanel.Window.Error.Changed:connect(function(property)
	if property == "Visible" then
		wait(3)
		cPanel.Window.Error.Visible = false
	end
end)

UserInputService.InputBegan:connect(function(input)
	if cInput then
		cInputB = input.KeyCode
		cInputT = input.UserInputType
	end
end)
UserInputService.InputChanged:connect(function(input)
	if cInput and (input.KeyCode == Enum.KeyCode.Thumbstick1 or input.KeyCode == Enum.KeyCode.Thumbstick2) then
		cInputB = input.KeyCode
		cInputT = input.UserInputType
	end
end)

cPanel.Toggle.MouseButton1Click:connect(function()
	controlsOpen = not controlsOpen
	if controlsOpen then
		cPanel.Toggle.BackgroundColor3 = Color3.new(1, 85 / 255, 0.5)
		cPanel.Window:TweenPosition(
			UDim2.new(0.5, -250, 0.5, -250),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Quad,
			0.7,
			true
		)
	else
		cPanel.Toggle.BackgroundColor3 = Color3.new(1, 170 / 255, 0)
		cPanel.Window:TweenPosition(
			UDim2.new(0.5, -250, 0, -500),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Quad,
			0.7,
			true
		)
	end
end)

cPanel.Window.Tabs.Keyboard.MouseButton1Click:connect(function()
	cPanel.Window.Content:TweenPosition(
		UDim2.new(0, 0, 0, 60),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Quad,
		0.4,
		true
	)
	cPanel.Window.Tabs.Keyboard:TweenPosition(
		UDim2.new(0, 5, 0, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Quad,
		0.4,
		true
	)
	cPanel.Window.Tabs.Mouse:TweenPosition(
		UDim2.new(0, 120, 0, -5),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Quad,
		0.4,
		true
	)
	cPanel.Window.Tabs.Controller:TweenPosition(
		UDim2.new(0, 235, 0, -5),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Quad,
		0.4,
		true
	)
end)

cPanel.Window.Tabs.Mouse.MouseButton1Click:connect(function()
	cPanel.Window.Content:TweenPosition(
		UDim2.new(-1, 0, 0, 60),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Quad,
		0.4,
		true
	)
	cPanel.Window.Tabs.Keyboard:TweenPosition(
		UDim2.new(0, 5, 0, -5),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Quad,
		0.4,
		true
	)
	cPanel.Window.Tabs.Mouse:TweenPosition(
		UDim2.new(0, 120, 0, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Quad,
		0.4,
		true
	)
	cPanel.Window.Tabs.Controller:TweenPosition(
		UDim2.new(0, 235, 0, -5),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Quad,
		0.4,
		true
	)
end)

cPanel.Window.Tabs.Controller.MouseButton1Click:connect(function()
	cPanel.Window.Content:TweenPosition(
		UDim2.new(-2, 0, 0, 60),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Quad,
		0.4,
		true
	)
	cPanel.Window.Tabs.Keyboard:TweenPosition(
		UDim2.new(0, 5, 0, -5),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Quad,
		0.4,
		true
	)
	cPanel.Window.Tabs.Mouse:TweenPosition(
		UDim2.new(0, 120, 0, -5),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Quad,
		0.4,
		true
	)
	cPanel.Window.Tabs.Controller:TweenPosition(
		UDim2.new(0, 235, 0, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Quad,
		0.4,
		true
	)
end)

wait(0.5)
cPanel.Toggle:TweenPosition(UDim2.new(0, 50, 1, -30), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.4, false)
for i = 1, 6 do
	cPanel.Toggle.BackgroundColor3 = Color3.new(100 / 255, 100 / 255, 100 / 255)
	wait(0.2)
	if controlsOpen then
		cPanel.Toggle.BackgroundColor3 = Color3.new(1, 85 / 255, 0.5)
	else
		cPanel.Toggle.BackgroundColor3 = Color3.new(1, 170 / 255, 0)
	end
	wait(0.2)
end
