--Avxnturador @ //INSPARE

local FE = workspace.FilteringEnabled
local car = script.Parent.Car.Value
local handler = car:WaitForChild("DS_Sounds")
local lastGear = 0
local Rev1 = 1500
local Rev2 = 2300
local Rev3 = 3700
local Rev4 = 5000

wait(0.5)

script:WaitForChild("DS1")
script:WaitForChild("DS2")
script:WaitForChild("DS3")
script:WaitForChild("DS4")

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","DS1",car.DriveSeat,script.DS1.SoundId,1,script.DS1.Volume,false)
handler:FireServer("newSound","DS2",car.DriveSeat,script.DS2.SoundId,1,script.DS2.Volume,false)
handler:FireServer("newSound","DS3",car.DriveSeat,script.DS3.SoundId,1,script.DS3.Volume,false)
handler:FireServer("newSound","DS4",car.DriveSeat,script.DS4.SoundId,1,script.DS4.Volume,false)

car.DriveSeat:WaitForChild("DS1")
car.DriveSeat:WaitForChild("DS2")
car.DriveSeat:WaitForChild("DS3")
car.DriveSeat:WaitForChild("DS4")


script.Parent.Values.Gear.Changed:connect(function()
	if lastGear>script.Parent.Values.Gear.Value then
		if ((script.Parent.Values.RPM.Value>=Rev1) and (script.Parent.Values.RPM.Value<Rev2)) then
			if FE then handler:FireServer("playSound","DS1") else car.DriveSeat.DS1:Play() end
		elseif ((script.Parent.Values.RPM.Value>=Rev2) and (script.Parent.Values.RPM.Value<Rev3)) then
			if FE then handler:FireServer("playSound","DS2") else car.DriveSeat.DS2:Play() end
		elseif ((script.Parent.Values.RPM.Value>=Rev3) and (script.Parent.Values.RPM.Value<Rev4)) then
			if FE then handler:FireServer("playSound","DS3") else car.DriveSeat.DS3:Play() end
		elseif (script.Parent.Values.RPM.Value>=Rev4) then
			if FE then handler:FireServer("playSound","DS4") else car.DriveSeat.DS4:Play() end
		end
	end
	lastGear = script.Parent.Values.Gear.Value
end)
