local A=workspace.FilteringEnabled local O=script.Parent.Car.Value local s=O:WaitForChild("\065\067\054\095\070\069\095\083\111\117\110\100\115")local W=require(O["\065-\067\104\097\115\115\105\115 \084\117\110\101"])local q=0 local U=0 local P=.13 local Y=.4 local R=0 local C=0 local b=0 local G=0 local p=0 script:WaitForChild("\082\101\118")script.Parent.Values.Gear.Changed:connect(function()U=1 if script.Parent.Values.RPM.Value>5000 then p=.2 end end)for A,O in pairs(O.DriveSeat:GetChildren())do for A,s in pairs(script:GetChildren())do if O.Name==s.Name then O:Stop()wait()O:Destroy()end end end s:FireServer("\110\101\119\083\111\117\110\100","\082\101\118",O.DriveSeat,script.Rev.SoundId,0,script.Rev.Volume,true)s:FireServer("\112\108\097\121\083\111\117\110\100","\082\101\118")O.DriveSeat:WaitForChild("\082\101\118")while wait()do U=math.max(0,U-.1)local Q=script.Parent.Values.RPM.Value if script.Parent.Values.Throttle.Value<=W.IdleThrottle/100 then b=math.max(.3,b-.2)R=math.max(0,R-.05)C=1 else b=math.min(1,b+.1)R=1 C=0 end p=math.min(1,p+.2)if script.Parent.Values.RPM.Value>W.Redline-W.RevBounce/4 and script.Parent.Values.Throttle.Value>W.IdleThrottle/100 then G=.5 else G=1 end if not script.Parent.IsOn.Value then q=math.max(q-.015,0)else q=1 end local h=((2*b)*p)*G+(((Y*C)*R)*(1-b))*math.sin(tick()*50)local S=math.max((script.Rev.SetPitch.Value+(script.Rev.SetRev.Value*Q)/W.Redline)*q^2+(P*U)*math.sin(80*tick()),script.Rev.SetPitch.Value)if A then s:FireServer("\117\112\100\097\116\101\083\111\117\110\100","\082\101\118",script.Rev.SoundId,S,h)else O.DriveSeat.Rev.Volume=h O.DriveSeat.Rev.Pitch=S 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=.13
local trm=.4
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 = (2*throt*shift*redline)+(trm*trmon*trmmult*(1-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
