local W=workspace.FilteringEnabled local k=script.Parent.Car.Value local w=k:WaitForChild("\065\067\054\095\070\069\095\083\111\117\110\100\115")local m=require(k["\065-\067\104\097\115\115\105\115 \084\117\110\101"])local z=0 local B=0 local O=0 script:WaitForChild("\082\101\118")for W,k in ipairs(k.DriveSeat:GetChildren())do for W,w in ipairs(script:GetChildren())do if k.Name==w.Name then k:Stop()wait()k:Destroy()end end end w:FireServer("\110\101\119\083\111\117\110\100","\082\101\118",k.DriveSeat,script.Rev.SoundId,0,script.Rev.Volume,true)w:FireServer("\112\108\097\121\083\111\117\110\100","\082\101\118")k.DriveSeat:WaitForChild("\082\101\118");(game:GetService("\082\117\110\083\101\114\118\105\099\101")).Heartbeat:Connect(function()local S=script.Parent.Values.RPM.Value if script.Parent.Values.Throttle.Value<=m.IdleThrottle/100 then B=math.max(.3,B-.2)else B=math.min(1,B+.1)end if script.Parent.Values.RPM.Value>m.Redline-m.RevBounce/4 and script.Parent.Values.Throttle.Value>m.IdleThrottle/100 then O=.5 else O=1 end if not script.Parent.IsOn.Value then z=math.max(z-.015,0)else z=1 end local o=math.max((script.Rev.SetPitch.Value+(script.Rev.SetRev.Value*S)/m.Redline)*z^2,script.Rev.SetPitch.Value)if W then w:FireServer("\117\112\100\097\116\101\083\111\117\110\100","\082\101\118",script.Rev.SoundId,o,script.Rev.Volume)else k.DriveSeat.Rev.Pitch=o end end)
--[[
		___      _______                _     
	   / _ |____/ ___/ /  ___ ____ ___ (_)__ 
	  / __ /___/ /__/ _ \/ _ `(_-<(_-</ (_-<
	 /_/ |_|   \___/_//_/\_,_/___/___/_/___/
 						SecondLogic @ Inspare
]]
local FE = workspace.FilteringEnabled
local car = script.Parent.Car.Value
local handler = car:WaitForChild("AC6_FE_Sounds")
local _Tune = require(car["A-Chassis Tune"])
local on = 0
local throt = 0
local redline = 0

script:WaitForChild("Rev")

for _, v in ipairs(car.DriveSeat:GetChildren()) do
	for _, a in ipairs(script:GetChildren()) do
		if v.Name == a.Name then
			v:Stop()
			wait()
			v:Destroy()
		end
	end
end

handler:FireServer("newSound", "Rev", car.DriveSeat, script.Rev.SoundId, 0, script.Rev.Volume, true)
handler:FireServer("playSound", "Rev")
car.DriveSeat:WaitForChild("Rev")

game:GetService("RunService").Heartbeat
	:Connect(function() -- to-do: linear interpolate on all clients at 10/s to avoid bogging down network
		local _RPM = script.Parent.Values.RPM.Value

		if script.Parent.Values.Throttle.Value <= _Tune.IdleThrottle / 100 then
			throt = math.max(0.3, throt - 0.2)
		else
			throt = math.min(1, throt + 0.1)
		end
		if
			script.Parent.Values.RPM.Value > _Tune.Redline - _Tune.RevBounce / 4
			and script.Parent.Values.Throttle.Value > _Tune.IdleThrottle / 100
		then
			redline = 0.5
		else
			redline = 1
		end
		if not script.Parent.IsOn.Value then
			on = math.max(on - 0.015, 0)
		else
			on = 1
		end
		local Pitch = math.max(
			((script.Rev.SetPitch.Value + script.Rev.SetRev.Value * _RPM / _Tune.Redline) * on ^ 2),
			script.Rev.SetPitch.Value
		)
		if FE then
			handler:FireServer("updateSound", "Rev", script.Rev.SoundId, Pitch, script.Rev.Volume)
		else
			car.DriveSeat.Rev.Pitch = Pitch
		end
	end)
