--//Misc2//--

local UserInputService = game:GetService("UserInputService")
 
local steer = 0
local throttle = 0
local brake = 0
 
local RTriggerValue = 0
local LTriggerValue = 0

stdz = script.Value

				
local PositiveEdgeButton = {
[Enum.KeyCode.ButtonL1]={f=function()
	if control.Value == "Controller" then
		if script.Parent.Storage.CurrentGear.Value ~= 1 then
	script.Parent.Functions.ShiftDownRequested.Value = true	
	end
	print("DOWN") --ADD LOWER LIMIT [AND UPPER 4 OTHER 1]
		end
	
end;deb=false};


[Enum.KeyCode.ButtonR1]={f=function() 
	if control.Value == "Controller" then
		if script.Parent.Storage.CurrentGear.Value ~= script.Parent.Storage.AmountOfGears.Value +2 then
		script.Parent.Functions.ShiftUpRequested.Value = true	
		end
		print("UP")
	end
end;deb=false}
}
 
function DealWithInput(input,IsRobloxFunction)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		local speed = carSeat.Velocity.magnitude
		if input.KeyCode == Enum.KeyCode.A then
			if input.UserInputState == Enum.UserInputState.Begin then 
			elseif input.UserInputState == Enum.UserInputState.End then 
			end
		end
		if input.KeyCode == Enum.KeyCode.D then
			if input.UserInputState == Enum.UserInputState.Begin then 
			elseif input.UserInputState == Enum.UserInputState.End then 
			end
		end
		if input.KeyCode == Enum.KeyCode.W then
			if input.UserInputState == Enum.UserInputState.Begin then 
			elseif input.UserInputState == Enum.UserInputState.End then 
			end
		end
		if input.KeyCode == Enum.KeyCode.S then
			if input.UserInputState == Enum.UserInputState.Begin then
			elseif input.UserInputState == Enum.UserInputState.End then
			end
		end
	end
	
	if input.KeyCode == Enum.KeyCode.ButtonX then 
				if input.UserInputState == Enum.UserInputState.Begin then print("help me sonny")
				
				elseif input.UserInputState == Enum.UserInputState.End then
				
				end
	end
	
	if control.Value == "Keyboard" then
			local LRpix = math.max(1,mouse.ViewSizeX*67/200)
			local dZoe = 0.04
			local MousePx = ((mouse.X-mouse.ViewSizeX/2)/LRpix) --print(MousePx)
			if math.abs(MousePx)<=dZoe then
				Gval = 0
			else
				Gval = (math.max(math.min((math.abs(MousePx)-dZoe),(1-dZoe)),0)/(1-dZoe))^1 * (MousePx / math.abs(MousePx))
			end
			
			--add if here
			---mouse.Button1Down:connect(function()
			---print("LeftClick")
			---end)
			
			---mouse.Button2Down:connect(function()
			---print("RightClick")
			--end)
	end
	
	if control.Value == "Controller" then
		if input.UserInputType.Name:find("Gamepad") then
			--------
			if input.KeyCode == Enum.KeyCode.Thumbstick1 then
				if input.Position.X > stdz.Value then
					if script.Parent.Storage.Control.Value == "Controller" then
					script.Parent.Storage.Steer.Value = (((input.Position.X)-stdz.Value)*(1/(1-stdz.Value))) end
				elseif input.Position.X < -stdz.Value then
					if script.Parent.Storage.Control.Value == "Controller" then
					script.Parent.Storage.Steer.Value = (((input.Position.X)+stdz.Value)*(1/(1-stdz.Value))) end
				else
					script.Parent.Storage.Steer.Value = 0
				end
			elseif input.KeyCode == Enum.KeyCode.ButtonR2 then
				RTriggerValue = input.Position.Z
				script.Parent.Storage.Throttle.Throttle.Value = RTriggerValue
			elseif input.KeyCode == Enum.KeyCode.ButtonL2 then
				LTriggerValue = input.Position.Z
				script.Parent.Storage.Brake.Value = LTriggerValue
			elseif PositiveEdgeButton[input.KeyCode] then
				local fn = PositiveEdgeButton[input.KeyCode]
				if input.Position.Z > 0.5 and not fn.deb then
					fn.deb = true
					fn.f()
				elseif input.Position.Z < 0.5 then
					fn.deb = false
				end
			end
		end
	end
end
UserInputService.InputBegan:connect(DealWithInput)
UserInputService.InputChanged:connect(DealWithInput)
UserInputService.InputEnded:connect(DealWithInput)
