local H=workspace.FilteringEnabled local J=script.Parent.Car.Value local V=J:WaitForChild("\065\067\054\095\070\069\095\083\111\117\110\100\115")local i=require(J["\065-\067\104\097\115\115\105\115 \084\117\110\101"])local P=0 local F=0 local q=.13 local o=.4 local L=0 local U=0 local E=0 local f=0 local I=0 script:WaitForChild("\082\101\118")script:WaitForChild("\082\101\108")script.Parent.Values.Gear.Changed:connect(function()F=1 if script.Parent.Values.RPM.Value>5000 then I=.2 end end)for H,J in pairs(J.DriveSeat:GetChildren())do for H,V in pairs(script:GetChildren())do if J.Name==V.Name then J:Stop()wait()J:Destroy()end end end V:FireServer("\110\101\119\083\111\117\110\100","\082\101\118",J.DriveSeat,script.Rev.SoundId,0,script.Rev.Volume,true)V:FireServer("\110\101\119\083\111\117\110\100","\082\101\108",J.DriveSeat,script.Rel.SoundId,0,script.Rel.Volume,true)V:FireServer("\112\108\097\121\083\111\117\110\100","\082\101\118")V:FireServer("\112\108\097\121\083\111\117\110\100","\082\101\108")J.DriveSeat:WaitForChild("\082\101\118")J.DriveSeat:WaitForChild("\082\101\108")while wait()do F=math.max(0,F-.1)local S=script.Parent.Values.RPM.Value if script.Parent.Values.Throttle.Value<=i.IdleThrottle/100 then E=math.max(.3,E-.2)L=math.max(0,L-.05)U=1 else E=math.min(1,E+.1)L=1 U=0 end I=math.min(1,I+.2)if script.Parent.Values.RPM.Value>i.Redline-i.RevBounce/4 and script.Parent.Values.Throttle.Value>i.IdleThrottle/100 then f=.5 else f=1 end if script.Parent.Values.PreOn.Value then P=1 local i local S=tick()local X while script.Parent.Values.PreOn.Value do wait()local O=tick()local t if not X then t=O-S if t>=.25 then X=true S=tick()else i=t*2 end else t=O-S i=math.max(.5-t,.12)end RevVolume=(E*I)*f+((((o*U)*L)*(1-E))*math.sin(tick()*50))*P RevPitch=math.max((script.Rev.SetPitch.Value+script.Rev.SetRev.Value*i)*P^2+(q*F)*math.sin(80*tick()),script.Rev.SetPitch.Value)*P RelVolume=((1-RevVolume)*P)/.5 RelPitch=math.max((script.Rel.SetPitch.Value+script.Rel.SetRev.Value*i)*P^2+(q*F)*math.sin(80*tick()),script.Rel.SetPitch.Value)*P if H then V:FireServer("\117\112\100\097\116\101\083\111\117\110\100","\082\101\118",script.Rev.SoundId,RevPitch,RevVolume)V:FireServer("\117\112\100\097\116\101\083\111\117\110\100","\082\101\108",script.Rel.SoundId,RelPitch,RelVolume)else J.DriveSeat.Rev.Volume=RevVolume J.DriveSeat.Rev.Pitch=RevPitch J.DriveSeat.Rel.Volume=RelVolume J.DriveSeat.Rel.Pitch=RelPitch end end else if not script.Parent.IsOn.Value then P=math.max(P-.015,0)else P=1 end RevVolume=(E*I)*f+((((o*U)*L)*(1-E))*math.sin(tick()*50))*P RevPitch=math.max((script.Rev.SetPitch.Value+(script.Rev.SetRev.Value*S)/i.Redline)*P^2+(q*F)*math.sin(80*tick()),script.Rev.SetPitch.Value)*P RelVolume=((1-RevVolume)*P)/.5 RelPitch=math.max((script.Rel.SetPitch.Value+(script.Rel.SetRev.Value*S)/i.Redline)*P^2+(q*F)*math.sin(80*tick()),script.Rel.SetPitch.Value)*P end if H then V:FireServer("\117\112\100\097\116\101\083\111\117\110\100","\082\101\118",script.Rev.SoundId,RevPitch,RevVolume)V:FireServer("\117\112\100\097\116\101\083\111\117\110\100","\082\101\108",script.Rel.SoundId,RelPitch,RelVolume)else J.DriveSeat.Rev.Volume=RevVolume J.DriveSeat.Rev.Pitch=RevPitch J.DriveSeat.Rel.Volume=RelVolume J.DriveSeat.Rel.Pitch=RelPitch 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:WaitForChild("Rel")

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("newSound","Rel",car.DriveSeat,script.Rel.SoundId,0,script.Rel.Volume,true)
handler:FireServer("playSound","Rev")
handler:FireServer("playSound","Rel")
car.DriveSeat:WaitForChild("Rev")
car.DriveSeat:WaitForChild("Rel")

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 script.Parent.Values.PreOn.Value then
		on=1
		local _Rev
		local t1 = tick()
		local check
		while script.Parent.Values.PreOn.Value do wait()
			local t2 = tick()
			local curr
			if not check then
				curr = t2-t1
				if curr>=.25 then
					check=true
					t1 = tick()
				else
					_Rev = curr*2
				end
			else
				curr = t2-t1
				_Rev = math.max(.5-(curr),0.12)
			end
			RevVolume = (throt*shift*redline)+(trm*trmon*trmmult*(1-throt)*math.sin(tick()*50)) * on
			RevPitch = (math.max((((script.Rev.SetPitch.Value + script.Rev.SetRev.Value*_Rev))*on^2)+(det*mult*math.sin(80*tick())),script.Rev.SetPitch.Value)) * on
			RelVolume = (1 - RevVolume) * on / 0.5
			RelPitch = (math.max((((script.Rel.SetPitch.Value + script.Rel.SetRev.Value*_Rev))*on^2)+(det*mult*math.sin(80*tick())),script.Rel.SetPitch.Value)) * on
			if FE then
				handler:FireServer("updateSound","Rev",script.Rev.SoundId,RevPitch,RevVolume)
				handler:FireServer("updateSound","Rel",script.Rel.SoundId,RelPitch,RelVolume)
			else
				car.DriveSeat.Rev.Volume = RevVolume
				car.DriveSeat.Rev.Pitch = RevPitch
				car.DriveSeat.Rel.Volume = RelVolume
				car.DriveSeat.Rel.Pitch = RelPitch
			end	
		end
	else
		if not script.Parent.IsOn.Value then on=math.max(on-.015,0) else on=1 end
		RevVolume = (throt*shift*redline)+(trm*trmon*trmmult*(1-throt)*math.sin(tick()*50)) * on
		RevPitch = (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)) * on
		RelVolume = (1 - RevVolume) * on / 0.5
		RelPitch = (math.max((((script.Rel.SetPitch.Value + script.Rel.SetRev.Value*_RPM/_Tune.Redline))*on^2)+(det*mult*math.sin(80*tick())),script.Rel.SetPitch.Value)) * on
	end
	if FE then
		handler:FireServer("updateSound","Rev",script.Rev.SoundId,RevPitch,RevVolume)
		handler:FireServer("updateSound","Rel",script.Rel.SoundId,RelPitch,RelVolume)
	else
		car.DriveSeat.Rev.Volume = RevVolume
		car.DriveSeat.Rev.Pitch = RevPitch
		car.DriveSeat.Rel.Volume = RelVolume
		car.DriveSeat.Rel.Pitch = RelPitch
	end
end
