local s=script.Parent.Car.Value local d=script.Parent.Values local h=require(s["\065-\067\104\097\115\115\105\115 \084\117\110\101"])local F=s:WaitForChild("\066\111\111\115\116\083\111\117\110\100\115")local o={}local A=d.Boost local M=d.Throttle local k=-1000 local function b(s,d)for h=0,3,1 do local F=Instance.new("\083\111\117\110\100")F.Parent=s.Body.Engine if h==1 then F.Name="\084\117\114\098\111"F.SoundId="\114\098\120\097\115\115\101\116\105\100\058\047\047"..d[1]F.Volume=0 F.RollOffMaxDistance=d[2]F.RollOffMinDistance=d[3]F.Looped=true elseif h==2 then F.Name="\083\117\112\101\114"F.SoundId="\114\098\120\097\115\115\101\116\105\100\058\047\047"..d[4]F.Volume=0 F.RollOffMaxDistance=d[5]F.RollOffMinDistance=d[6]F.Looped=true elseif h==3 then F.Name="\066\111\118"F.SoundId="\114\098\120\097\115\115\101\116\105\100\058\047\047"..d[7]F.Volume=0 F.RollOffMaxDistance=d[8]F.RollOffMinDistance=d[9]F.Looped=false end F:Play()table.insert(o,h,F)end end local function i(s,d)if o[1].Volume~=d[1]then o[1].Volume=d[1]o[1].Pitch=d[2]o[2].Volume=d[3]o[2].Pitch=d[4]o[3].Volume=d[5]o[3].Pitch=d[6]end end local function V()for s,d in pairs(o)do d:Play()end end local function m()for s,d in pairs(o)do d:Stop()end end local function t(s)info[1]=TurboVol*math.floor(d.BoostTurbo.Value)info[2]=TurboSetPitch+TurboPitchIncrease*d.BoostTurbo.Value info[5]=BovVol*math.floor(d.BoostTurbo.Value)info[6]=BovSetPitch+BovPitchIncrease*d.BoostTurbo.Value end local function c(s)info[3]=SuperVol*d.BoostSuper.Value info[4]=SuperSetPitch+SuperPitchIncrease*d.BoostSuper.Value end local function x(s)info[1]=TurboVol*math.floor(d.BoostTurbo.Value)info[2]=TurboSetPitch+TurboPitchIncrease*d.BoostTurbo.Value info[3]=SuperVol*d.BoostSuper.Value info[4]=SuperSetPitch+SuperPitchIncrease*d.BoostSuper.Value info[5]=BovVol*math.floor(d.BoostTurbo.Value)info[6]=BovSetPitch+BovPitchIncrease*d.BoostTurbo.Value end info={TurboId;TurboRollOffMax,TurboRollOffMin,SuperId;SuperRollOffMax;SuperRollOffMin;BovId,BovRollOffMax,BovRollOffMin}if FE==true then F:FireServer(s,"\099\114\101\097\116\101",info)if d.Parent.IsOn.Value==true then F:FireServer(s,"\112\108\097\121")else F:FireServer(s,"\115\116\111\112")end elseif FE==false then b(s,info)if d.Parent.IsOn.Value==true then V()else m()end end if BovId>0 then M.Changed:Connect(function()local d=A.Value wait(.1)if A.Value+BovSensitivity<d then if FE==true then F:FireServer(s,"\098\111\118\112\108\097\121")else o[3]:Play()end end end)end if h.Turbochargers>0 and h.Superchargers==0 then info[3]=0 info[4]=0 A.Changed:Connect(function(d)t()if FE==true then F:FireServer(s,"\117\112\100\097\116\101",nil,info)else i(o,info)end end)elseif h.Superchargers>0 and h.Turbochargers==0 then info[1]=0 info[2]=0 info[5]=0 info[6]=0 A.Changed:Connect(function(d)c(d)if FE==true then F:FireServer(s,"\117\112\100\097\116\101",nil,info)else i(o,info)end end)elseif h.Turbochargers>0 and h.Superchargers>0 then A.Changed:Connect(function(d)x(d)if FE==true then F:FireServer(s,"\117\112\100\097\116\101",nil,info)else i(o,info)end end)end d.Parent.IsOn.Changed:Connect(function(d)if d==false and FE==true then F:FireServer(s,"\115\116\111\112")elseif d==true and FE==true then F:FireServer(s,"\112\108\097\121")elseif d==false and FE==false then m()elseif d==true and FE==false then V()end end)
-- End of Editable Values

local car = script.Parent.Car.Value
local values = script.Parent.Values
local tune = require(car["A-Chassis Tune"])
local event = car:WaitForChild("BoostSounds")
local newsounds = {}

local bst = values.Boost
local throt = values.Throttle
local pbst = -1000

local function create(car, info)
	for k = 0, 3 do
		local ns = Instance.new("Sound")
		ns.Parent = car.Body.Engine
		if k == 1 then
			ns.Name = "Turbo"
			ns.SoundId = "rbxassetid://" .. info[1]
			ns.Volume = 0
			ns.RollOffMaxDistance = info[2]
			ns.RollOffMinDistance = info[3]
			ns.Looped = true
		elseif k == 2 then
			ns.Name = "Super"
			ns.SoundId = "rbxassetid://" .. info[4]
			ns.Volume = 0
			ns.RollOffMaxDistance = info[5]
			ns.RollOffMinDistance = info[6]
			ns.Looped = true
		elseif k == 3 then
			ns.Name = "Bov"
			ns.SoundId = "rbxassetid://" .. info[7]
			ns.Volume = 0
			ns.RollOffMaxDistance = info[8]
			ns.RollOffMinDistance = info[9]
			ns.Looped = false
		end
		ns:Play()
		table.insert(newsounds, k, ns)
	end
end
local function update(sounds, info)
	if newsounds[1].Volume ~= info[1] then
		newsounds[1].Volume = info[1]
		newsounds[1].Pitch = info[2]
		newsounds[2].Volume = info[3]
		newsounds[2].Pitch = info[4]
		newsounds[3].Volume = info[5]
		newsounds[3].Pitch = info[6]
	end
end
local function play()
	for _, s in pairs(newsounds) do
		s:Play()
	end
end
local function stop()
	for _, s in pairs(newsounds) do
		s:Stop()
	end
end
local function turboupd(x)
	info[1] = TurboVol * math.floor(values.BoostTurbo.Value)
	info[2] = TurboSetPitch + (TurboPitchIncrease * values.BoostTurbo.Value)
	info[5] = BovVol * math.floor(values.BoostTurbo.Value)
	info[6] = BovSetPitch + (BovPitchIncrease * values.BoostTurbo.Value)
end
local function superupd(x)
	info[3] = SuperVol * values.BoostSuper.Value
	info[4] = SuperSetPitch + (SuperPitchIncrease * values.BoostSuper.Value)
end
local function twinupd(x)
	info[1] = TurboVol * math.floor(values.BoostTurbo.Value)
	info[2] = TurboSetPitch + (TurboPitchIncrease * values.BoostTurbo.Value)
	info[3] = SuperVol * values.BoostSuper.Value
	info[4] = SuperSetPitch + (SuperPitchIncrease * values.BoostSuper.Value)
	info[5] = BovVol * math.floor(values.BoostTurbo.Value)
	info[6] = BovSetPitch + (BovPitchIncrease * values.BoostTurbo.Value)
end

info = {
	TurboId,
	TurboRollOffMax,
	TurboRollOffMin,
	SuperId,
	SuperRollOffMax,
	SuperRollOffMin,
	BovId,
	BovRollOffMax,
	BovRollOffMin,
}
if FE == true then
	event:FireServer(car, "create", info)

	if values.Parent.IsOn.Value == true then
		event:FireServer(car, "play")
	else
		event:FireServer(car, "stop")
	end
elseif FE == false then
	create(car, info)

	if values.Parent.IsOn.Value == true then
		play()
	else
		stop()
	end
end

if BovId > 0 then
	throt.Changed:Connect(function()
		local pbst = bst.Value
		wait(0.1)
		if bst.Value + BovSensitivity < pbst then
			if FE == true then
				event:FireServer(car, "bovplay")
			else
				newsounds[3]:Play()
			end
		end
	end)
end

if tune.Turbochargers > 0 and tune.Superchargers == 0 then
	info[3] = 0
	info[4] = 0
	bst.Changed:Connect(function(x)
		turboupd()
		if FE == true then
			event:FireServer(car, "update", nil, info)
		else
			update(newsounds, info)
		end
	end)
elseif tune.Superchargers > 0 and tune.Turbochargers == 0 then
	info[1] = 0
	info[2] = 0
	info[5] = 0
	info[6] = 0
	bst.Changed:Connect(function(x)
		superupd(x)
		if FE == true then
			event:FireServer(car, "update", nil, info)
		else
			update(newsounds, info)
		end
	end)
elseif tune.Turbochargers > 0 and tune.Superchargers > 0 then
	bst.Changed:Connect(function(x)
		twinupd(x)
		if FE == true then
			event:FireServer(car, "update", nil, info)
		else
			update(newsounds, info)
		end
	end)
end

values.Parent.IsOn.Changed:Connect(function(v)
	if v == false and FE == true then
		event:FireServer(car, "stop")
	elseif v == true and FE == true then
		event:FireServer(car, "play")
	elseif v == false and FE == false then
		stop()
	elseif v == true and FE == false then
		play()
	end
end)
