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

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
