local C=workspace.FilteringEnabled local v=script.Parent.Car.Value local o=v:WaitForChild("\065\067\054\095\070\069\095\083\111\117\110\100\115\077\105\115\099")local X=require(v["\065-\067\104\097\115\115\105\115 \084\117\110\101"])local R=0 local q=0 local J=.13 script:WaitForChild("\082\101\108")script:WaitForChild("\083\116\097\114\116")script.Parent.Values.Gear.Changed:connect(function()q=1 end)for C,v in pairs(v.DriveSeat:GetChildren())do for C,o in pairs(script:GetChildren())do if v.Name==o.Name then v:Stop()wait()v:Destroy()end end end o:FireServer("\110\101\119\083\111\117\110\100","\082\101\108",v.DriveSeat,script.Rel.SoundId,0,script.Rel.Volume,true)o:FireServer("\110\101\119\083\111\117\110\100","\083\116\097\114\116",v.DriveSeat,script.Start.SoundId,1,script.Start.Volume,false)o:FireServer("\112\108\097\121\083\111\117\110\100","\082\101\108")v.DriveSeat:WaitForChild("\082\101\108")v.DriveSeat:WaitForChild("\083\116\097\114\116")while wait()do q=math.max(0,q-.1)local y=script.Parent.Values.RPM.Value if script.Parent.Values.PreOn.Value then o:FireServer("\112\108\097\121\083\111\117\110\100","\083\116\097\114\116")wait(1)else if not script.Parent.IsOn.Value then R=math.max(R-.015,0)else R=1 end RelVolume=2*(1-math.min((script.Parent.Values.RPM.Value*2)/X.Redline,1))RelPitch=math.max((script.Rel.SetPitch.Value+(script.Rel.SetRev.Value*y)/X.Redline)*R^2+(J*q)*math.sin(80*tick()),script.Rel.SetPitch.Value)*R end if C then o:FireServer("\117\112\100\097\116\101\083\111\117\110\100","\082\101\108",script.Rel.SoundId,RelPitch,RelVolume)else v.DriveSeat.Rel.Volume=RelVolume v.DriveSeat.Rel.Pitch=RelPitch end end
--[[
		___      _______                _     
	   / _ |____/ ___/ /  ___ ____ ___ (_)__ 
	  / __ /___/ /__/ _ \/ _ `(_-<(_-</ (_-<
	 /_/ |_|   \___/_//_/\_,_/___/___/_/___/
 						SecondLogic @ Inspare
]]
local FE = workspace.FilteringEnabled
local car = script.Parent.Car.Value
local handler = car:WaitForChild("AC6_FE_SoundsMisc")
local _Tune = require(car["A-Chassis Tune"])
local on = 0
local mult = 0
local det = 0.13

script:WaitForChild("Rel")
script:WaitForChild("Start")

script.Parent.Values.Gear.Changed:connect(function()
	mult = 1
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", "Rel", car.DriveSeat, script.Rel.SoundId, 0, script.Rel.Volume, true)
handler:FireServer("newSound", "Start", car.DriveSeat, script.Start.SoundId, 1, script.Start.Volume, false)
handler:FireServer("playSound", "Rel")
car.DriveSeat:WaitForChild("Rel")
car.DriveSeat:WaitForChild("Start")

while wait() do
	mult = math.max(0, mult - 0.1)
	local _RPM = script.Parent.Values.RPM.Value
	if script.Parent.Values.PreOn.Value then
		handler:FireServer("playSound", "Start")
		wait(1)
	else
		if not script.Parent.IsOn.Value then
			on = math.max(on - 0.015, 0)
		else
			on = 1
		end
		RelVolume = 2 * (1 - math.min(((script.Parent.Values.RPM.Value * 2) / _Tune.Redline), 1))
		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", "Rel", script.Rel.SoundId, RelPitch, RelVolume)
	else
		car.DriveSeat.Rel.Volume = RelVolume
		car.DriveSeat.Rel.Pitch = RelPitch
	end
end
