local N=workspace.FilteringEnabled local p=script.Parent.Car.Value local f=p:WaitForChild("\065\067\054\095\070\069\095\083\111\117\110\100\115")local B=require(p["\065-\067\104\097\115\115\105\115 \084\117\110\101"])local P=0 local y=0 local M=0 local J=0 local A=0 local Z=0 local x=0 local H=0 local Y=0 script:WaitForChild("\082\101\118")script.Parent.Values.Gear.Changed:connect(function()y=1 if script.Parent.Values.RPM.Value>5000 then Y=.2 end end)for N,p in pairs(p.DriveSeat:GetChildren())do for N,f in pairs(script:GetChildren())do if p.Name==f.Name then p:Stop()wait()p:Destroy()end end end f:FireServer("\110\101\119\083\111\117\110\100","\082\101\118",p.DriveSeat,script.Rev.SoundId,0,script.Rev.Volume,true)f:FireServer("\112\108\097\121\083\111\117\110\100","\082\101\118")p.DriveSeat:WaitForChild("\082\101\118")while wait()do y=math.max(0,y-.1)local g=script.Parent.Values.RPM.Value if script.Parent.Values.Throttle.Value<=B.IdleThrottle/100 then x=math.max(.3,x-.2)A=math.max(0,A-.05)Z=1 else x=math.min(1,x+.1)A=1 Z=0 end Y=math.min(1,Y+.2)if script.Parent.Values.RPM.Value>B.Redline-B.RevBounce/4 and script.Parent.Values.Throttle.Value>B.IdleThrottle/100 then H=.5 else H=1 end if not script.Parent.IsOn.Value then P=math.max(P-.015,0)else P=1 end local a=((3*x)*Y)*H+(((J*Z)*A)*(3-x))*math.sin(tick()*50)local o=math.max((script.Rev.SetPitch.Value+(script.Rev.SetRev.Value*g)/B.Redline)*P^2+(M*y)*math.sin(80*tick()),script.Rev.SetPitch.Value)if N then f:FireServer("\117\112\100\097\116\101\083\111\117\110\100","\082\101\118",script.Rev.SoundId,o,a)else p.DriveSeat.Rev.Volume=a p.DriveSeat.Rev.Pitch=o end end

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 mult=0
local det=0
local trm=0
local trmmult=0
local trmon=0
local throt=0
local redline=0
local shift=0

script:WaitForChild("Rev")

script.Parent.Values.Gear.Changed:connect(function()
	mult=1
	if script.Parent.Values.RPM.Value>5000 then
		shift=.2
	end
end)

for i,v in pairs(car.DriveSeat:GetChildren()) do
	for _,a in pairs(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")

while wait() do
	mult=math.max(0,mult-.1)
	local _RPM = script.Parent.Values.RPM.Value
	
	if script.Parent.Values.Throttle.Value <= _Tune.IdleThrottle/100 then
		throt = math.max(.3,throt-.2)
		trmmult = math.max(0,trmmult-.05)
		trmon = 1		
	else
		throt = math.min(1,throt+.1)
		trmmult = 1
		trmon = 0		
	end	
	shift = math.min(1,shift+.2)	
	if script.Parent.Values.RPM.Value > _Tune.Redline-_Tune.RevBounce/4 and script.Parent.Values.Throttle.Value > _Tune.IdleThrottle/100 then
		redline=.5
	else
		redline=1
	end
	if not script.Parent.IsOn.Value then on=math.max(on-.015,0) else on=1 end
	local Volume = (3*throt*shift*redline)+(trm*trmon*trmmult*(3-throt)*math.sin(tick()*50))
	local Pitch = math.max((((script.Rev.SetPitch.Value + script.Rev.SetRev.Value*_RPM/_Tune.Redline))*on^2)+(det*mult*math.sin(80*tick())),script.Rev.SetPitch.Value)
	if FE then
		handler:FireServer("updateSound","Rev",script.Rev.SoundId,Pitch,Volume)
	else
		car.DriveSeat.Rev.Volume = Volume
		car.DriveSeat.Rev.Pitch = Pitch
	end
end
