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