local p=workspace.FilteringEnabled local E=script.Parent.Car.Value local u=E:WaitForChild("\065\067\054\095\070\069\095\083\111\117\110\100\115")local z=require(E["\065-\067\104\097\115\115\105\115 \084\117\110\101"])local a=0 local X=0 local F=.13 local Q=.4 local k=0 local e=0 local h=0 local i=0 local B=0 script:WaitForChild("\082\101\118")script.Parent.Values.Gear.Changed:connect(function()X=1 if script.Parent.Values.RPM.Value>5000 then B=.2 end end)for p,E in pairs(E.DriveSeat:GetChildren())do for p,u in pairs(script:GetChildren())do if E.Name==u.Name then E:Stop()wait()E:Destroy()end end end u:FireServer("\110\101\119\083\111\117\110\100","\082\101\118",E.DriveSeat,script.Rev.SoundId,0,script.Rev.Volume,true)u:FireServer("\112\108\097\121\083\111\117\110\100","\082\101\118")E.DriveSeat:WaitForChild("\082\101\118")while wait()do X=math.max(0,X-.1)local v=script.Parent.Values.RPM.Value if script.Parent.Values.Throttle.Value<=z.IdleThrottle/100 then h=math.max(.3,h-.2)k=math.max(0,k-.05)e=1 else h=math.min(1,h+.1)k=1 e=0 end B=math.min(1,B+.2)if script.Parent.Values.RPM.Value>z.Redline-z.RevBounce/4 and script.Parent.Values.Throttle.Value>z.IdleThrottle/100 then i=.5 else i=1 end if not script.Parent.IsOn.Value then a=math.max(a-.015,0)else a=1 end local U=((2*h)*B)*i+(((Q*e)*k)*(1-h))*math.sin(tick()*50)local o=math.max((script.Rev.SetPitch.Value+(script.Rev.SetRev.Value*v)/z.Redline)*a^2+(F*X)*math.sin(80*tick()),script.Rev.SetPitch.Value)if p then if(script.Parent:FindFirstChild("\068\114\105\118\101\077\111\100\101")).Value~="\067\111\109\102\111\114\116"then u:FireServer("\117\112\100\097\116\101\083\111\117\110\100","\082\101\118",script.Rev.SoundId,o,U)else u:FireServer("\117\112\100\097\116\101\083\111\117\110\100","\082\101\118",script.Rev.SoundId,o/1.2,U/1.2)end else if(script.Parent:FindFirstChild("\068\114\105\118\101\077\111\100\101")).Value~="\067\111\109\102\111\114\116"then E.DriveSeat.Rev.Volume=U E.DriveSeat.Rev.Pitch=o else E.DriveSeat.Rev.Volume=U/1.75 E.DriveSeat.Rev.Pitch=o/1.5 end 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 mult = 0
local det = 0.13
local trm = 0.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 = 0.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 - 0.1)
	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)
		trmmult = math.max(0, trmmult - 0.05)
		trmon = 1
	else
		throt = math.min(1, throt + 0.1)
		trmmult = 1
		trmon = 0
	end
	shift = math.min(1, shift + 0.2)
	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 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
		if script.Parent:FindFirstChild("DriveMode").Value ~= "Comfort" then
			handler:FireServer("updateSound", "Rev", script.Rev.SoundId, Pitch, Volume)
		else
			handler:FireServer("updateSound", "Rev", script.Rev.SoundId, Pitch / 1.2, Volume / 1.2)
		end
	else
		if script.Parent:FindFirstChild("DriveMode").Value ~= "Comfort" then
			car.DriveSeat.Rev.Volume = Volume
			car.DriveSeat.Rev.Pitch = Pitch
		else
			car.DriveSeat.Rev.Volume = Volume / 1.75
			car.DriveSeat.Rev.Pitch = Pitch / 1.5
		end
	end
end
