Is it possible to select all parts in model with script

Is it possible to select all parts in model and anchor it with only one script. For example, I have 500 part in model and I want all of them to anchor and then unchor it after 15 second, how can I do that?

If you want to click / press the models, this might help -
https://developer.roblox.com/en-us/api-reference/function/Selection/Get

https://education.roblox.com/en-us/resources/pairs-and-ipairs-intro

Try using for i,v in pairs()

A simple example of what you can do:

local model = workspace.Model

for i, v in pairs(model:GetDescendants()) do -- this get severy single thing inside the model, for every single thing inside that model do:
if v:IsA("Part") then -- check if the child is a part
   v.Anchored = true -- v is the part
end
end

Find out more here:
https://education.roblox.com/en-us/resources/pairs-and-ipairs-intro

local Workspace = workspace
local Model = Workspace.Model --Reference to model.

for _, Descendant in ipairs(Model:GetDescendants()) do
	if Descendant:IsA("BasePart") then
		Descendant.Anchored = true
	end
end

@Forummer
@MrColola
I believe he meant to make it so that when you select all the models/parts with your cursor, you make them Unanchored with a script.

I think he meant to make it β€œon live” ( while on edit mode), and not on testing mode. I might be wrong, but the op did not clarify that.

with only one script,

I want all of them to anchor and then unchor it after 15 second

The op did clarify.

local Workspace = workspace
local Model = Workspace.Model --Reference to model.

local Descendants = Model:GetDescendants()
for _, Descendant in ipairs(Descendants) do
	if Descendant:IsA("BasePart") then
		Descendant.Anchored = true
	end
end
task.wait(15)
for _, Descendant in ipairs(Descendants) do
	if Descendant:IsA("BasePart") then
		Descendant.Anchored = false
	end
end
1 Like