Is it possible to select multiple specific children at once?

So I was working on a settings Gui for my game, and I came across a problem. I wanted to make the lava animation turn off when the button is clicked, but I’m not sure how to select all of the lava scripts inside the lava part, which are in different models.
image
image
Each map has the same lava model as shown in the first image. So is it possible to select all of the Water Texture scripts in the game without typing out a line of code for each part of lava?

Also, I want to disable all particles in the game with the button. I’m also confused on how to do that.

Let me know if you don’t understand and I can elaborate.

I think you’ll just have to use getdescendants then loop through that for a name and/or class match. Same for the particles, you can ‘search’ for particle emitters and enable/disable.

Might be better to use tagging(https://developer.roblox.com/en-us/api-reference/class/CollectionService), idk.

look at the second script example here thinking about your particles:
https://developer.roblox.com/en-us/api-reference/function/Instance/GetDescendants

1 Like

For the maps:

local mapsFolder = game:GetService('ServerStorage').Maps

-- Loop through maps
for _, map in pairs(mapsFolder:GetChildren()) do
  if (map:FindFirstChild('Lava')) then -- does a child called Lava exist?
    if (map.Lava:FindFirstChild('RisingLava')) then -- does a child of Lava called RisingLava exist?
      local risingLava = map.Lava:FindFirstChild('RisingLava')
      -- do stuff
    end
  end
end

For particles:

for _, child in pairs(workspace:GetDescendants()) do
  if (child:IsA('ParticleEmitter')) then -- Check if its a particle emitter
    child.Enabled = false
  end
end
1 Like

For the lava one, I made:

local mapsFolder = game:GetService('ServerStorage').Maps

for _, map in pairs(mapsFolder:GetChildren()) do
			if (map:FindFirstChild('Lava')) then -- does a child called Lava exist?
				if (map.Lava:FindFirstChild('RisingLava')) then -- does a child of Lava called RisingLava exist?
					local risingLava = map.Lava:FindFirstChild('RisingLava')
					risingLava["Water Texture Script"].Enabled = false
				end
			end
		end

My question is, will it select the first lava part it finds, or will it select all of the parts? I’m asking because every map has multiple lava parts.

You’re looking for the First part /map that is named “Lava”, then you’re looking for the First Child of lava named “RisingLava” it’ll only get the first instances, that’s what FindFirstChild does i believe

would “getdescendants” not help you in this case? instead of getting the children (the maps), it gets All of the children, even if it’s a parent of something else.

For example;
Game.map.lava.lavarising
Map:GetChildren would only return lava.
Map:GetDescendants will return lava and lava rising
(Read up on Instance:GetDescendants (roblox.com) for more information, basically what highness was referring to.)

1 Like

This should work, but can you select a specific object with GetDescendants? If so, this would be a lot more helpful.

Yeah, you can use IsA: To identify different Types of instances

(For example,

if P:IsA("MeshPart") then

)

If you need multiple things with you but they have the same same but different classtypes, then just use .Name Like this;

for _, Thing in pairs (Tree:GetDescendants()) do
if Thing.Name == "Leaf" then
Thing.Color = Color3.FromRGB(0,255,0)
1 Like

The problem with your situation is that the client can’t disable server scripts. You should create particles on the client and manually apply it to each of the lava models on each client. That way, you can easily disable particles on a single client.

It’s bad practice to have a script for each lava model, anyway. They should be handled in bulk under a single script.

1 Like

Ok, I get it. I got a problem with @AstrealDev script, which said “Map is not a valid member of ServerStorage”. This is confusing because there is a folder in ServerStorage called maps. Can you explain why this error appears?

here just replace the mapsFolder line with this:

local mapsFolder = game:GetService('ServerStorage'):WaitForChild('Maps')

might be that the folder just hasn’t loaded yet

Reminder that LocalScripts cannot access ServerStorage or ServerScriptService. Can you confirm you are not using a LocalScript to handle this? By the way, any changes you make will affect every single player on the server if you are using a normal Script, which is why I’m against the idea of handling all these particles on the server in the first place.

I am using a LocalScript to do this. Why can’t a LocalScript acces ServerStorage or ServerScriptService? It kinda ruins the entire point of the settings if it cannot access it. And is there another way to do this if the LocalScript won’t work?

As the name suggests, it’s server-side only. Why else would it be called ServerStorage if it wasn’t? Developers sometimes put confidential stuff behind there that the client shouldn’t be able to access sometimes. If you want the client to see it, put it under ReplicatedStorage, which as its name suggests, is replicated to clients as well.

As I suggested earlier, handle all effects on the client. Don’t use server scripts to add particle effects, do it all on the client by handling it bulk under a single LocalScript.

I am a beginner at scripting, so I am slightly confused. What exactly am I to put under ReplicatedStorage? And also, what do you mean by handling things on the client?

I’m not sure if you know this or if I misunderstood, but the particles are an effect inside the brick. I don’t add them with any script. I am just trying make it possible to disable them.

ReplicatedStorage houses objects which the client should be able to access, so housing sensitive data here is a bad idea, whereas ServerStorage is never available to the client, so housing ModuleScripts with things like API keys is relatively safe here.


I think I misunderstood you before - I thought you meant the scripts inside the lava add and remove particles. All the same though, you shouldn’t have individual scripts for each lava block. It’s much more sensible to handle them in one place.

For example, instead of have a Script under each block in a setup with a folder under Workspace called “Blocks” which has this script in each object under it:

local Model = script.Parent
local Part = Model.Part

Part.Name = "BasePart"

Instead, you could simply put this in a Script under ServerScriptService:

local Blocks = workspace.Blocks

-- Event handler
local function onBlockAdded(Block)
    Block.Part.Name = "BasePart"
end

-- Runs whenever a block is parented to Blocks
Blocks.ChildAdded:Connect(onBlockAdded)

-- Runs on any block under workspace.Blocks
for _, block in ipairs(Blocks:GetChildren()) do
    onBlockAdded(block)
end

And this would be much more manageable.

In your case, let’s say Maps is under ReplicatedStorage this time, and this is code in a LocalScript under StarterPlayerScripts.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Maps = ReplicatedStorage:WaitForChild("Maps") -- wait for it to exist, since it might not be available straight away

local function onMapAdded(Map)
    local Lava = Map:FindFirstChild("Lava")
    if Lava then
        local Part = Lava:FindFirstChild("Rising Lava")
        for _,child in ipairs(Part and Part:GetChildren() or {}) do
            if child:IsA("ParticleEmitter") then
                child.Enabled = false
            end
        end
    end
end

Maps.ChildAdded:Connect(onMapAdded)

for _, map in ipairs(Maps:GetChildren()) do
    onMapAdded(map)
end

This code will disable any ParticleEmitters under that Rising Lava block.

1 Like

Thank you. I think I get it now. One more question before I go to sleep. Do things in ReplicatedStorage have to be duplicated and put into the workspace? That is what I am doing with my maps right now.

That depends on what you are trying to do, but in most cases, cloning is the way to go.

If you clone it from the server, any changes the client made in ReplicatedStorage will not be honoured, so you will need to amend this code so that it applies to whichever map is currently in the workspace. Therefore, the code I provided will only work as is if the maps are cloned locally (so not from the server).

1 Like

From the server, do you mean from ServerStorage? I’m not sure how to amend the code to apply to whichever map is currently in the workspace, as most people will turn off the particles/lava animation while in the lobby, when there is no map spawned in.

So basically I have to put the maps in ReplicatedStorage, change my main code to make it spawn from there, and allow settings to access it?