So I was making the QOL update and Roblox made my code deprecated. But when I reverted versions, the music zone code was working perfect. So I don’t know why the music zone doesn’t work. I tried the “new” zone function and it spammed me a bunch of errors. I don’t know why my music zone script doesn’t work anymore.
local collectionservice = game:GetService("CollectionService")
local zones = workspace:WaitForChild("Zones")
local parts = collectionservice:GetTagged("ZoneMain")
local partsbuilding = collectionservice:GetTagged("ZoneBuilding")
local tweenservice = game:GetService("TweenService")
local runservice = game:GetService("RunService")
local inside = false
local volume = 1
local events = game.ReplicatedStorage:WaitForChild("Events")
local enabled = true
local insidebuilding = false
events.Muted.OnClientEvent:Connect(function()
enabled = false
end)
events.Unmuted.OnClientEvent:Connect(function()
enabled = true
end)
local function inZone(zone)
if not zone.Ambiences.Ambience.Playing then zone.Ambiences.Ambience:Play() end
tweenservice:Create(zone.Ambiences.Ambience, TweenInfo.new(0.2), {Volume = volume}):Play()
local equalizer = zone.Ambiences.Ambience.EqualizerSoundEffect
local tweeninfo = TweenInfo.new(0.2)
local highgain = tweenservice:Create(equalizer, tweeninfo, {HighGain = 0})
local midgain = tweenservice:Create(equalizer, tweeninfo, {MidGain = 0})
local lowgain = tweenservice:Create(equalizer, tweeninfo, {LowGain = 0})
highgain:Play()
midgain:Play()
lowgain:Play()
end
local function kindainZone(zone)
local equalizer = zone.Ambiences.Ambience.EqualizerSoundEffect
local tweeninfo = TweenInfo.new(0.2)
local highgain = tweenservice:Create(equalizer, tweeninfo, {HighGain = -50})
local midgain = tweenservice:Create(equalizer, tweeninfo, {MidGain = -20})
local lowgain = tweenservice:Create(equalizer, tweeninfo, {LowGain = 10})
highgain:Play()
midgain:Play()
lowgain:Play()
tweenservice:Create(zone.Ambiences.Ambience, TweenInfo.new(0.2), {Volume = volume}):Play()
end
local function leftZone(zone)
tweenservice:Create(zone.Ambiences.Ambience, TweenInfo.new(0.2), {Volume = 0}):Play()
end
runservice.RenderStepped:Connect(function()
for i, zone in pairs(parts) do
if enabled then
if zone.Parent == zones.Main then
volume = 1
inside = false
--if the inbuilding attribute in the character is true then volume equals zero
if game.Players.LocalPlayer.Character:WaitForChild("InBuilding").Value == true then
volume = 0
else
volume = 1
end
local region = Region3.new(zone.Position - zone.Size/2, zone.Position + zone.Size/2)
local regionparts = workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())
for _, zoneregion in pairs(regionparts) do
if zoneregion:FindFirstAncestor(game.Players.LocalPlayer.Name) then
inside = true
break
else
inside = false
end
end
if inside then
inZone(zone)
break
else
kindainZone(zone)
end
end
else
volume = 0
leftZone(zone)
end
end
for i, zonebuilding in pairs(partsbuilding) do
if enabled then
if zonebuilding.Parent == zones.Buildings then
volume = 1
inside = false
--if the inbuilding attribute in the character is true then volume equals zero
if game.Players.LocalPlayer.Character:WaitForChild("InBuilding").Value == false then
volume = 0
else
volume = 1
end
local region = Region3.new(zonebuilding.Position - zonebuilding.Size/2, zonebuilding.Position + zonebuilding.Size/2)
local regionparts = workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())
for _, zoneregion in pairs(regionparts) do
if zoneregion:FindFirstAncestor(game.Players.LocalPlayer.Name) then
inside = true
break
else
inside = false
end
end
if inside then
inZone(zonebuilding)
game.Players.LocalPlayer.Character:WaitForChild("InBuilding").Value = true
break
else
leftZone(zonebuilding)
game.Players.LocalPlayer.Character:WaitForChild("InBuilding").Value = false
end
end
else
volume = 0
leftZone(zonebuilding)
end
end
end)