local y=workspace.FilteringEnabled local c=script.Parent.Car.Value local T=c:WaitForChild("\065\067\054\095\070\069\095\083\111\117\110\100\115")local F=require(c.Tuner)local E=0 local H=0 local l=0 script:WaitForChild("\082\101\118")script:WaitForChild("\069\108\101\099")for y,c in pairs(c.DriveSeat:GetChildren())do for y,T in pairs(script:GetChildren())do if c.Name==T.Name then c:Stop()wait()c:Destroy()end end end T:FireServer("\110\101\119\083\111\117\110\100","\082\101\118",c.DriveSeat,script.Rev.SoundId,0,script.Rev.SetVol.Value,true)T:FireServer("\110\101\119\083\111\117\110\100","\069\108\101\099",c.DriveSeat,script.Elec.SoundId,0,script.Elec.SetVol.Value,true)T:FireServer("\112\108\097\121\083\111\117\110\100","\082\101\118")T:FireServer("\112\108\097\121\083\111\117\110\100","\069\108\101\099")c.DriveSeat:WaitForChild("\082\101\118")c.DriveSeat:WaitForChild("\069\108\101\099")while wait()do local y=script.Parent.Values.RPM.Value if script.Parent.Values.Throttle.Value<=F.IdleThrottle/100 then H=math.max(.3,H-.2)else H=math.min(1,H+.1)end if script.Parent.Values.RPM.Value>F.Redline-F.RevBounce/4 and script.Parent.Values.Throttle.Value>F.IdleThrottle/100 then l=.5 else l=1 end if not script.Parent.IsOn.Value then E=math.max(E-.015,0)else E=1 end local c=script.Rev.SetVol.Value local n=script.Elec.SetVol.Value if not F.Engine then c=0 end if not F.Electric then n=0 end local Z=math.max((script.Rev.SetPitch.Value+(script.Rev.SetRev.Value*y)/F.Redline)*E^2,script.Rev.SetPitch.Value)local j=math.max((script.Elec.SetPitch.Value+(script.Elec.SetRev.Value*y)/F.Redline)*E^2,script.Elec.SetPitch.Value)T:FireServer("\117\112\100\097\116\101\083\111\117\110\100","\082\101\118",script.Rev.SoundId,Z,c)T:FireServer("\117\112\100\097\116\101\083\111\117\110\100","\069\108\101\099",script.Elec.SoundId,j,n)end
--[[
		___      _______                _     
	   / _ |____/ ___/ /  ___ ____ ___ (_)__ 
	  / __ /___/ /__/ _ \/ _ `(_-<(_-</ (_-<
	 /_/ |_|   \___/_//_/\_,_/___/___/_/___/
 						SecondLogic @ Inspare
]]
local FE = workspace.FilteringEnabled
local car = script.Parent.Car.Value
local handler = car:WaitForChild("AC6_FE_Sounds")
local _Tune = require(car["Tuner"])
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
