local K=workspace.FilteringEnabled local n=script.Parent.Car.Value local B=n:WaitForChild("\065\067\054\095\070\069\095\083\111\117\110\100\115")local D=require(n["\065-\067\104\097\115\115\105\115 \084\117\110\101"])local f=0 local k=0 local I=0 script:WaitForChild("\082\101\118")for K,n in ipairs(n.DriveSeat:GetChildren())do for K,B in ipairs(script:GetChildren())do if n.Name==B.Name then n:Stop()wait()n:Destroy()end end end B:FireServer("\110\101\119\083\111\117\110\100","\082\101\118",n.DriveSeat,script.Rev.SoundId,0,script.Rev.Volume,true)B:FireServer("\112\108\097\121\083\111\117\110\100","\082\101\118")n.DriveSeat:WaitForChild("\082\101\118");(game:GetService("\082\117\110\083\101\114\118\105\099\101")).Heartbeat:Connect(function()local S=script.Parent.Values.RPM.Value if script.Parent.Values.Throttle.Value<=D.IdleThrottle/100 then k=math.max(.3,k-.2)else k=math.min(1,k+.1)end if script.Parent.Values.RPM.Value>D.Redline-D.RevBounce/4 and script.Parent.Values.Throttle.Value>D.IdleThrottle/100 then I=.5 else I=1 end if not script.Parent.IsOn.Value then f=math.max(f-.015,0)else f=1 end local g=math.max((script.Rev.SetPitch.Value+(script.Rev.SetRev.Value*S)/D.Redline)*f^2,script.Rev.SetPitch.Value)if K then B:FireServer("\117\112\100\097\116\101\083\111\117\110\100","\082\101\118",script.Rev.SoundId,g,script.Rev.Volume)else n.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 throt=0
local redline=0

script:WaitForChild("Rev")

for _,v in ipairs(car.DriveSeat:GetChildren()) do
	for _,a in ipairs(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:GetService("RunService").Heartbeat:Connect(function() -- to-do: linear interpolate on all clients at 10/s to avoid bogging down network
	local _RPM = script.Parent.Values.RPM.Value
	
	if script.Parent.Values.Throttle.Value <= _Tune.IdleThrottle/100 then
		throt = math.max(.3,throt-.2)	
	else
		throt = math.min(1,throt+.1)	
	end	
	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 Pitch = math.max((((script.Rev.SetPitch.Value + script.Rev.SetRev.Value*_RPM/_Tune.Redline))*on^2),script.Rev.SetPitch.Value)
	if FE then
		handler:FireServer("updateSound","Rev",script.Rev.SoundId,Pitch,script.Rev.Volume)
	else
		car.DriveSeat.Rev.Pitch = Pitch
	end
end)
