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

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(.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,.5)
		cPanel.Window:TweenPosition(UDim2.new(0.5, -250,0.5, -250),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.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,.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,.4,true)
	cPanel.Window.Tabs.Keyboard:TweenPosition(UDim2.new(0, 5, 0, 0),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.4,true)
	cPanel.Window.Tabs.Mouse:TweenPosition(UDim2.new(0, 120, 0, -5),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.4,true)
	cPanel.Window.Tabs.Controller:TweenPosition(UDim2.new(0, 235, 0, -5),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.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,.4,true)
	cPanel.Window.Tabs.Keyboard:TweenPosition(UDim2.new(0, 5, 0, -5),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.4,true)
	cPanel.Window.Tabs.Mouse:TweenPosition(UDim2.new(0, 120, 0, 0),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.4,true)
	cPanel.Window.Tabs.Controller:TweenPosition(UDim2.new(0, 235, 0, -5),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.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,.4,true)
	cPanel.Window.Tabs.Keyboard:TweenPosition(UDim2.new(0, 5, 0, -5),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.4,true)
	cPanel.Window.Tabs.Mouse:TweenPosition(UDim2.new(0, 120, 0, -5),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.4,true)
	cPanel.Window.Tabs.Controller:TweenPosition(UDim2.new(0, 235, 0, 0),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.4,true)
end)

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