For i,v in pairs() not working

Then why not use the built in function in the API?
.getZones() ZoneController - ZonePlus

how do i use it?
robloxlimitlimit

for _,v in ZoneController.getZones() do
	print(v) -- your zones are  here
end

Yeah, so if you want to remove all children, you don’t need a for parameter. I just solved your problem.

ZoneController:ClearAllChildren()

no,
that is not what i need to do

Did you read the original post? He’s not trying to delete all the children; he’s trying to create zones from the parts in a folder.

Also, @weakroblox35, that will do nothing because no zones are being created.

Play your game and send a screenshot of the workspace.

1 Like

Like this?

local RegionTextGui = script:WaitForChild("RegionText")
local RS = game:GetService("ReplicatedStorage")
local Skies = RS:WaitForChild("Skies")

local TweenService = game:GetService("TweenService")

local plr = game:GetService("Players").LocalPlayer
local PlayingSong = game:GetService("SoundService").PlayingSong

local ZonePlus = require(game:GetService("ReplicatedStorage").Modules.Zone)
local ZoneController = require(game:GetService("ReplicatedStorage").Modules.Zone.ZoneController)

local Zones = workspace:WaitForChild("SoundsRegions"):GetChildren()

for _, zone_part in ZoneController.getZones() do
	print(Zones)
	local trigger = ZonePlus.new(zone_part)
	trigger.playerEntered:Connect(function(player)
		if player == plr then
			TweenService:Create(PlayingSong, TweenInfo.new(.75), {Volume = 0}):Play()
			wait(.75)
			PlayingSong.SoundId = zone_part.Sound.SoundId
			local nextVolume = zone_part.Sound.Volume
			TweenService:Create(PlayingSong, TweenInfo.new(.5), {Volume = nextVolume}):Play()
		end
	end)
end

ZoneController.setGroup("SoundRegions", {
	onlyEnterOnceExitedAll = true;
})

That could be easily solved if OP read the docs. Method - ZonePlus

Yeah you can try that.

ok, it didnt work
limitlimitlimitlimit

Last bet is to read the API’s docs, or use functions in the resource.

no but the thing is, i literally use this script for my other games, and it works perfectly fine

The issue is not that OP isn’t using the module correctly. It’s that there’s nothing in the folder to begin with so no zones are being created.

@Xatiuqe, play your game and send a screenshot of workspace with the SoundsRegions folder expanded.

1 Like

i did, like 3 times

Few things.

  1. You should be using .localPlayerEntered if you only want to detect if the local player enters
  2. The zone parts may not load in time, which is why you have to add a .ChildAdded to check for any new zone parts

Code:

--//Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SoundService = game:GetService("SoundService")
local TweenService = game:GetService("TweenService")

--//Modules
local ZonePlus = require(ReplicatedStorage.Modules.Zone)
local ZoneController = require(ReplicatedStorage.Modules.Zone.ZoneController)
ZoneController.setGroup("SoundRegions", {onlyEnterOnceExitedAll = true})

--//Variables
local PlayingSong = SoundService.PlayingSong
local Skies = ReplicatedStorage:WaitForChild("Skies")
local RegionTextGui = script:WaitForChild("RegionText")
local Zones = workspace.SoundsRegions

--//Functions
local function InitializeSoundRegion(part)
	print("Initialized Zone")
	local zone = ZonePlus.new(part)

	zone.localPlayerEntered:Connect(function(player)
		TweenService:Create(PlayingSong, TweenInfo.new(.75), {Volume = 0}):Play()
		task.wait(.75)

		PlayingSong.SoundId = part.Sound.SoundId
		
		local nextVolume = part.Sound.Volume
		TweenService:Create(PlayingSong, TweenInfo.new(.5), {Volume = nextVolume}):Play()
	end)
end

Zones.ChildAdded:Connect(InitializeSoundRegion)

for _, zone_part in ipairs(Zones:GetChildren()) do
	task.spawn(InitializeSoundRegion, zone_part)
end

Also, why is everyone just saying random things to add to the conversation that aren’t even related? I know you want your solution but please, try to at least help OP instead of asking questions that were already answered, and then proceeding to tell him useless solutions without any actual research.

(Talking to you @weakroblox35 and @DiamondDrencher1)

3 Likes

For individuals joining this thread later who might not wish to read through all the prior messages, it’s important to note that a screenshot of their workspace has already been provided. The issue lies in the fact that the content isn’t replicating to the client or is being deleted. Therefore, it’s crucial to concentrate on comprehending and resolving this specific problem.

got this error,
StarterPlayer.StarterPlayerScripts.Areas:26: attempt to index nil with ‘SoundId’

I made a typo, fixed:

--//Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SoundService = game:GetService("SoundService")
local TweenService = game:GetService("TweenService")

--//Modules
local ZonePlus = require(ReplicatedStorage.Modules.Zone)
local ZoneController = require(ReplicatedStorage.Modules.Zone.ZoneController)
ZoneController.setGroup("SoundRegions", {onlyEnterOnceExitedAll = true})

--//Variables
local PlayingSong = SoundService.PlayingSong
local Skies = ReplicatedStorage:WaitForChild("Skies")
local RegionTextGui = script:WaitForChild("RegionText")
local Zones = workspace.SoundsRegions

--//Functions
local function InitializeSoundRegion(part)
	print("Initialized Zone")
	local zone = ZonePlus.new(part)

	zone.localPlayerEntered:Connect(function(player)
		TweenService:Create(PlayingSong, TweenInfo.new(.75), {Volume = 0}):Play()
		task.wait(.75)

		PlayingSong.SoundId = part.Sound.SoundId
		
		local nextVolume = part.Sound.Volume
		TweenService:Create(PlayingSong, TweenInfo.new(.5), {Volume = nextVolume}):Play()
	end)
end

Zones.ChildAdded:Connect(InitializeSoundRegion)

for _, zone_part in ipairs(Zones:GetChildren()) do
	task.spawn(InitializeSoundRegion, zone_part)
end

Sorry you had to deal with 3 different people who had no clue what they were doing and were just trying to get a solution.

1 Like

I wasn’t trying to get a solution lol I was just suggesting OP to read the docs.

FYI, I’m not solely concentrating on trying to get a solution.

I guess I misread what you were actually trying to get fixed.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.