Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to get Instance.new to apply to more than one brick?

Asked by 7 years ago
Edited 7 years ago

So I don't know if this is correct but I made this so that once it is ran, it finds Plane in the workspace and it is supposed to take all of the parts named Brick in the model but I think it either only applies BlockMesh to one part rather than all of them. How could I get it to be applied to all the parts in the model that are named Brick?

local mesh = Instance.new("BlockMesh", game.Workspace.Plane.Brick)
print("Mesh Applied")
0
idk, but i do know one way you can make your script shorter. don't say mesh.Parent = game.Workspace.Plane.Brick. say Instance.new("BlockMesh", game.Workspace.Plane.Brick) wookey12 174 — 7y
0
Thank you! BunnyFilms1 297 — 7y
0
Keep in mind, friend, that using the syntax Instance.new(className, Parent) is not at all recommended if you plan on customizing the object. Always set properties before parenting instances, because doing so on the DataModel is more expensive. saenae 318 — 7y

2 answers

Log in to vote
1
Answered by
MrHerkes 166
7 years ago
for _, v in pairs(game.Workspace.Plane:GetChildren()) do
    if v.Name == "Brick" then
        local mesh = Instance.new("BlockMesh", v)
        print("Mesh Applied")
    end
end

What this does is that if it finds the part named "Brick" in your plane, it will apply the BlockMesh to every part named "Brick".

Ad
Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

Try this

for _,v in pairs(game.Workspace.Plane:GetChildren()) do
    if v.Name == "Brick" then
local mesh = Instance.new("BlockMesh",v)
print("Mesh Applied")
    end
    end

edit: Accidently forgot to change something in this.

Answer this question