local b=workspace.FilteringEnabled local W=script.Parent.Car.Value local s=W:WaitForChild("\065\067\054\095\070\069\095\083\111\117\110\100\115")local D=require(W["\065-\067\104\097\115\115\105\115 \084\117\110\101"])local j=0 local m=0 local K=0 script:WaitForChild("\082\101\118")script:WaitForChild("\069\108\101\099")for b,W in pairs(W.DriveSeat:GetChildren())do for b,s in pairs(script:GetChildren())do if W.Name==s.Name then W:Stop()wait()W:Destroy()end end end s:FireServer("\110\101\119\083\111\117\110\100","\082\101\118",W.DriveSeat,script.Rev.SoundId,0,script.Rev.SetVol.Value,true)s:FireServer("\110\101\119\083\111\117\110\100","\069\108\101\099",W.DriveSeat,script.Elec.SoundId,0,script.Elec.SetVol.Value,true)s:FireServer("\112\108\097\121\083\111\117\110\100","\082\101\118")s:FireServer("\112\108\097\121\083\111\117\110\100","\069\108\101\099")W.DriveSeat:WaitForChild("\082\101\118")W.DriveSeat:WaitForChild("\069\108\101\099")while wait()do local b=script.Parent.Values.RPM.Value if script.Parent.Values.Throttle.Value<=D.IdleThrottle/100 then m=math.max(.3,m-.2)else m=math.min(1,m+.1)end if script.Parent.Values.RPM.Value>D.Redline-D.RevBounce/4 and script.Parent.Values.Throttle.Value>D.IdleThrottle/100 then K=.5 else K=1 end if not script.Parent.IsOn.Value then j=math.max(j-.015,0)else j=1 end local W=script.Rev.SetVol.Value local k=script.Elec.SetVol.Value if not D.Engine then W=0 end if not D.Electric then k=0 end local P=math.max((script.Rev.SetPitch.Value+(script.Rev.SetRev.Value*b)/D.Redline)*j^2,script.Rev.SetPitch.Value)local F=math.max((script.Elec.SetPitch.Value+(script.Elec.SetRev.Value*b)/D.Redline)*j^2,script.Elec.SetPitch.Value)s:FireServer("\117\112\100\097\116\101\083\111\117\110\100","\082\101\118",script.Rev.SoundId,P,W)s:FireServer("\117\112\100\097\116\101\083\111\117\110\100","\069\108\101\099",script.Elec.SoundId,F,k)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 throt = 0
local redline = 0

script:WaitForChild("Rev")
script:WaitForChild("Elec")

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

while wait() do
	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)
	else
		throt = math.min(1, throt + 0.1)
	end
	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 RevVol = script.Rev.SetVol.Value
	local ElecVol = script.Elec.SetVol.Value
	if not _Tune.Engine then
		RevVol = 0
	end
	if not _Tune.Electric then
		ElecVol = 0
	end
	local RevPitch = math.max(
		((script.Rev.SetPitch.Value + script.Rev.SetRev.Value * _RPM / _Tune.Redline) * on ^ 2),
		script.Rev.SetPitch.Value
	)
	local ElecPitch = math.max(
		((script.Elec.SetPitch.Value + script.Elec.SetRev.Value * _RPM / _Tune.Redline) * on ^ 2),
		script.Elec.SetPitch.Value
	)
	handler:FireServer("updateSound", "Rev", script.Rev.SoundId, RevPitch, RevVol)
	handler:FireServer("updateSound", "Elec", script.Elec.SoundId, ElecPitch, ElecVol)
end
