local W=workspace.FilteringEnabled local w=script.Parent.Car.Value local g=w:WaitForChild("\065\067\054\095\070\069\095\083\111\117\110\100\115")local l=require(w["\065-\067\104\097\115\115\105\115 \084\117\110\101"])local N=0 local y=0 local c=.13 local B=.4 local e=0 local a=0 local Q=0 local X=0 local L=0 script:WaitForChild("\082\101\118")script.Parent.Values.Gear.Changed:connect(function()y=1.2 if script.Parent.Values.RPM.Value>5000 then L=.2 end end)for W,w in pairs(w.DriveSeat:GetChildren())do for W,g in pairs(script:GetChildren())do if w.Name==g.Name then w:Stop()wait()w:Destroy()end end end g:FireServer("\110\101\119\083\111\117\110\100","\082\101\118",w.DriveSeat,script.Rev.SoundId,0,script.Rev.Volume,true)g:FireServer("\112\108\097\121\083\111\117\110\100","\082\101\118")w.DriveSeat:WaitForChild("\082\101\118")game["\082\117\110 \083\101\114\118\105\099\101"].Stepped:connect(function()y=math.max(0,y-.1)local C=script.Parent.Values.RPM.Value if script.Parent.Values.Throttle.Value<=l.IdleThrottle/100 then Q=math.max(.3,Q-.2)e=math.max(0,e-.05)a=1 else Q=math.min(1,Q+.1)e=1 a=0 end L=math.min(1,L+.2)if script.Parent.Values.RPM.Value>l.Redline-l.RevBounce/4 and script.Parent.Values.Throttle.Value>l.IdleThrottle/100 then X=.5 else X=1 end if not script.Parent.IsOn.Value then N=math.max(N-.015,0)else N=1 end local U=((1*Q)*L)*X+(((B*a)*e)*(1-Q))*math.sin(tick()*50)local G=math.max((script.Rev.SetPitch.Value+(script.Rev.SetRev.Value*C)/l.Redline)*N^2+(c*y)*math.sin(80*tick()),script.Rev.SetPitch.Value)if W then g:FireServer("\117\112\100\097\116\101\083\111\117\110\100","\082\101\118",script.Rev.SoundId,G,U)else w.DriveSeat.Rev.Volume=U w.DriveSeat.Rev.Pitch=G 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.2
	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")

game["Run Service"].Stepped:connect(function()
	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 = (1*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)
