--[[
		___      _______                _     
	   / _ |____/ ___/ /  ___ ____ ___ (_)__ 
	  / __ /___/ /__/ _ \/ _ `(_-<(_-</ (_-<
	 /_/ |_|   \___/_//_/\_,_/___/___/_/___/
 						SecondLogic @ Inspare
]]

local FE = workspace.FilteringEnabled
local car = script.Parent.Car.Value
local _Tune = require(car["A-Chassis Tune"])
local on = 0


script:WaitForChild("Wheel")

if not FE then
	for i,v in pairs(car.Body.WHEEL:GetChildren()) do
		for _,a in pairs(script:GetChildren()) do
			if v.Name==a.Name then v:Stop() wait() v:Destroy() end
		end
	end
	for i,v in pairs(script:GetChildren()) do
		v.Parent=car.Body.WHEEL
	end
	
	
	car.Body.WHEEL.Wheel:Play()
	
	while wait() do
		local _RPM = script.Parent.Values.RPM.Value
		
		if not car.DriveSeat.IsOn.Value then on=math.max(on-.015,0) else on=1 end
		
car.Body.WHEEL.Wheel.Pitch = (car.Body.WHEEL.Wheel.SetPitch.Value + car.Body.WHEEL.Wheel.SetRev.Value*_RPM/_Tune.Redline)*on^2

		if _RPM == 700 then
	
			car.Body.WHEEL.Wheel.Volume = 0.1
	
			
		end

	end
else
	local handler = car.AC6_FE_Sounds
	
	handler:FireServer("newSound","Wheel",car.Body.WHEEL,script.Wheel.SoundId,0,script.Wheel.Volume,true)
	handler:FireServer("playSound","Wheel")
	
	local pitch4=0
	while wait() do
		local _RPM = script.Parent.Values.RPM.Value
		
		if not car.DriveSeat.IsOn.Value then on=math.max(on-.015,0) else on=1 end
		
		pitch4 = (script.Wheel.SetPitch.Value + script.Wheel.SetRev.Value*_RPM/_Tune.Redline)*on^2
	
		handler:FireServer("updateSound","Wheel",script.idle.SoundId,pitch4,script.Wheel.Volume)
	end
end


