local P=workspace.FilteringEnabled local l=script.Parent.Car.Value local r=require(l["\065-\067\104\097\115\115\105\115 \084\117\110\101"])local O=0 script:WaitForChild("\082\101\118")script:WaitForChild("\084\117\114\098\111")if not P then for P,l in pairs(l.Body.ENGINE:GetChildren())do for P,r in pairs(script:GetChildren())do if l.Name==r.Name then l:Stop()wait()l:Destroy()end end end for P,r in pairs(script:GetChildren())do r.Parent=l.Body.ENGINE end l.Body.ENGINE.Rev:Play()l.Body.ENGINE.idle:Play()while wait()do local P=script.Parent.Values.RPM.Value if not l.DriveSeat.IsOn.Value then O=math.max(O-.015,0)else O=1 end l.Body.ENGINE.Rev.Pitch=(l.Body.ENGINE.Rev.SetPitch.Value+(l.Body.ENGINE.Rev.SetRev.Value*P)/r.Redline)*O^2 l.Body.ENGINE.Turbo.Pitch=(l.Body.ENGINE.Turbo.SetPitch.Value+(l.Body.ENGINE.Turbo.SetRev.Value*P)/r.Redline)*O^2 l.Body.ENGINE.idle.Pitch=(l.Body.ENGINE.idle.SetPitch.Value+(l.Body.ENGINE.Turbo.SetRev.Value*P)/r.Redline)*O^2 if P==700 then l.Body.ENGINE.idle.Volume=.1 l.Body.ENGINE.Turbo.Volume=.2 l.Body.ENGINE.Rev.Volume=0 else l.Body.ENGINE.Rev.Volume=.2 l.Body.ENGINE.idle.Volume=0 end end else local P=l.AC6_FE_Sounds P:FireServer("\110\101\119\083\111\117\110\100","\082\101\118",l.Body.ENGINE,script.Rev.SoundId,0,script.Rev.Volume,true)P:FireServer("\112\108\097\121\083\111\117\110\100","\082\101\118")P:FireServer("\110\101\119\083\111\117\110\100","\084\117\114\098\111",l.Body.ENGINE,script.Turbo.SoundId,0,script.Turbo.Volume,true)P:FireServer("\112\108\097\121\083\111\117\110\100","\084\117\114\098\111")P:FireServer("\110\101\119\083\111\117\110\100","\105\100\108\101",l.Body.ENGINE,script.idle.SoundId,0,script.Turbo.Volume,true)P:FireServer("\112\108\097\121\083\111\117\110\100","\105\100\108\101")local v=0 local S=0 local z=0 while wait()do local x=script.Parent.Values.RPM.Value if not l.DriveSeat.IsOn.Value then O=math.max(O-.015,0)else O=1 end v=(script.Rev.SetPitch.Value+(script.Rev.SetRev.Value*x)/r.Redline)*O^2 S=(script.Turbo.SetPitch.Value+(script.Turbo.SetRev.Value*x)/r.Redline)*O^2 z=(script.idle.SetPitch.Value+(script.idle.SetRev.Value*x)/r.Redline)*O^2 P:FireServer("\117\112\100\097\116\101\083\111\117\110\100","\082\101\118",script.Rev.SoundId,v,script.Rev.Volume)P:FireServer("\117\112\100\097\116\101\083\111\117\110\100","\084\117\114\098\111",script.Turbo.SoundId,S,script.Turbo.Volume)P:FireServer("\117\112\100\097\116\101\083\111\117\110\100","\105\100\108\101",script.idle.SoundId,z,script.idle.Volume)end end
--[[
		___      _______                _     
	   / _ |____/ ___/ /  ___ ____ ___ (_)__ 
	  / __ /___/ /__/ _ \/ _ `(_-<(_-</ (_-<
	 /_/ |_|   \___/_//_/\_,_/___/___/_/___/
 						SecondLogic @ Inspare
]]
local FE = workspace.FilteringEnabled
local car = script.Parent.Car.Value
local _Tune = require(car["A-Chassis Tune"])
local on = 0

script:WaitForChild("Rev")
script:WaitForChild("Turbo")

if not FE then
	for i, v in pairs(car.Body.ENGINE:GetChildren()) do
		for _, a in pairs(script:GetChildren()) do
			if v.Name == a.Name then
				v:Stop()
				wait()
				v:Destroy()
			end
		end
	end
	for i, v in pairs(script:GetChildren()) do
		v.Parent = car.Body.ENGINE
	end

	car.Body.ENGINE.Rev:Play()
	car.Body.ENGINE.idle:Play()

	while wait() do
		local _RPM = script.Parent.Values.RPM.Value

		if not car.DriveSeat.IsOn.Value then
			on = math.max(on - 0.015, 0)
		else
			on = 1
		end
		car.Body.ENGINE.Rev.Pitch = (
			car.Body.ENGINE.Rev.SetPitch.Value + car.Body.ENGINE.Rev.SetRev.Value * _RPM / _Tune.Redline
		) * on ^ 2
		car.Body.ENGINE.Turbo.Pitch = (
			car.Body.ENGINE.Turbo.SetPitch.Value + car.Body.ENGINE.Turbo.SetRev.Value * _RPM / _Tune.Redline
		) * on ^ 2
		car.Body.ENGINE.idle.Pitch = (
			car.Body.ENGINE.idle.SetPitch.Value + car.Body.ENGINE.Turbo.SetRev.Value * _RPM / _Tune.Redline
		) * on ^ 2

		if _RPM == 700 then
			car.Body.ENGINE.idle.Volume = 0.1 -- 0/.07
			car.Body.ENGINE.Turbo.Volume = 0.2
			car.Body.ENGINE.Rev.Volume = 0
		else
			car.Body.ENGINE.Rev.Volume = 0.2
			car.Body.ENGINE.idle.Volume = 0
			--	car.Body.ENGINE.Turbo:Stop()
		end
	end
else
	local handler = car.AC6_FE_Sounds
	handler:FireServer("newSound", "Rev", car.Body.ENGINE, script.Rev.SoundId, 0, script.Rev.Volume, true)
	handler:FireServer("playSound", "Rev")
	handler:FireServer("newSound", "Turbo", car.Body.ENGINE, script.Turbo.SoundId, 0, script.Turbo.Volume, true)
	handler:FireServer("playSound", "Turbo")
	handler:FireServer("newSound", "idle", car.Body.ENGINE, script.idle.SoundId, 0, script.Turbo.Volume, true)
	handler:FireServer("playSound", "idle")

	local pitch = 0
	local pitch2 = 0
	local pitch3 = 0

	while wait() do
		local _RPM = script.Parent.Values.RPM.Value

		if not car.DriveSeat.IsOn.Value then
			on = math.max(on - 0.015, 0)
		else
			on = 1
		end
		pitch = (script.Rev.SetPitch.Value + script.Rev.SetRev.Value * _RPM / _Tune.Redline) * on ^ 2
		pitch2 = (script.Turbo.SetPitch.Value + script.Turbo.SetRev.Value * _RPM / _Tune.Redline) * on ^ 2
		pitch3 = (script.idle.SetPitch.Value + script.idle.SetRev.Value * _RPM / _Tune.Redline) * on ^ 2

		handler:FireServer("updateSound", "Rev", script.Rev.SoundId, pitch, script.Rev.Volume)
		handler:FireServer("updateSound", "Turbo", script.Turbo.SoundId, pitch2, script.Turbo.Volume)
		handler:FireServer("updateSound", "idle", script.idle.SoundId, pitch3, script.idle.Volume)
	end
end
