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

Script breaks when adding multiple names?

Asked by 8 years ago
Edited 8 years ago

Edit: Sorry for the strange/bad title, I had to pass the "Your title should be specific! Describe your problem concisely." problem ASAP.

So, I've a model called "Model6" and all parts/unions in it are called "Toro". I've made this so when a player joins the game, all the parts/unions in the model disappear(using CanCollide and Transparency properties).

modelOfBricks = game.Workspace.Model6
nameOfBricks = "Toro"

for i,v in pairs(modelOfBricks:GetChildren()) do
    if v.Name == nameOfBricks then
        v.Transparency = 1
        v.CanCollide = false
    end
end

However, when changing the name of one of the parts/unions in Model6 to "Toro2" and then adding "Toro2" to the line nameOfBricks = the works properly and makes all parts/unions disappear except the one with the name "Toro2", here is the :

modelOfBricks = game.Workspace.Model6
nameOfBricks = "Toro","Toro2"

for i,v in pairs(modelOfBricks:GetChildren()) do
    if v.Name == nameOfBricks then
        v.Transparency = 1
        v.CanCollide = false
    end
end

I also tried writing "Toro, Toro2" instead, but it didn't work. Output says nothing.

1 answer

Log in to vote
1
Answered by
Netflixy 126
8 years ago
Edited 8 years ago

Instead of using nameOfBricks = "Toro","Toro2", you should use a table.

nameOfBricks = {"Toro","Toro2"}

And then in your loop, check if it is in the table.

Full script:

modelOfBricks = game.Workspace.Model6
nameOfBricks = {"Toro","Toro2"}  --The table


for i,v in pairs(modelOfBricks:GetChildren()) do
    for i=1,#nameOfBricks do --Adding another loop to check if it is in the table
        if v.Name == nameOfBricks[i] then
             v.Transparency = 1
             v.CanCollide = false
        end
    end
end
0
Worked, thanks. kudorey619 138 — 8y
0
;) Netflixy 126 — 8y
Ad

Answer this question