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

How do I use getChildren on a model to disable all the scripts within it?

Asked by 4 years ago
Edited 4 years ago

Basically I need to disable the scripts inside a model which has different models within it that hold scripts, localscripts, and modulescripts. The main model though will be within the script on the tree level. I don't know how to script so that's why I am asking for the code. Sorry for any inconveniences.

(UPDATE: So far can't get any of the first 4 scripts below to work for this. No clue why they don't work guessing scripts don't run in Workspace then idk.

4 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Use :IsA to detect the class of the instance

for i,v in pairs(workspace.Model:GetChildren())do
    if v:IsA("Script") then
        v.Disabled=true
    end
end
0
did the disable wrong :) ForeverBrown 356 — 4y
0
lol EmbeddedHorror 299 — 4y
0
oops sorry for downvote EmbeddedHorror 299 — 4y
0
i think get descendatns would be better in this situation, and its better to explain to him what the loop does EmbeddedHorror 299 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

a for loop would be useful for this.


part=your part for i,v in pairs(part:GetChildren()) do--[[ u could also use :GetDescendants() to get the children of the children]] -- i is the index, v is the value if v:IsA("Script") or v:IsA("LocalScript") then v.Disabled=true end end

tell me if it helped ;)

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

you would need to loop through all of the models using a pairs loop.

for i,v in pairs() do

end)

that is a pairs loop. looks sorta similar to a for i = x,x,x loop. "i" is the index. you can change the index to any letter you want. "v" is the value. you can also change it to any letter you want. pairs is used in tables and getchildren and some other things. there is also ipairs that stops when there is a nil value but that won't be used. in the parentheses, you would put the table or the model where you want to get the children. and whatever is in the parentheses is what the value is.

for i,v in pairs(NameOfTheModelWithScripts:GetChildren()) do

end)

since we have access to whatever is in the model, we can change the property. but what if there is another object in the model that isn't a script and doesn't have the disabled property. well, you can use if v:IsA("PutClassName") then or if v.ClassName == "PutClassName" then IsA is recommended "v" inside of one of those if statements would only affect objects with the certain class. but outside of it, it will affect object with any class. the class name is usually the name that the object starts out when inserting an object (that rule doesn't apply for some objects. such as a shirt. when a shirt is inserted, studio will automatically change its name to "Clothing") oh and remember when putting the class name, make sure it includes the capitals. it's case sensitive. oh and the classname is a visible property.

for i,v in pairs(NameOfTheModelWithScripts:GetChildren()) do
    if v:IsA("ClassNameHere") then
        --do what ever to the object
    end
end)
0
why downvote :( ZorbaTheGreatGreek 59 — 4y
0
Use :IsA instead of v.ClassName ForeverBrown 356 — 4y
0
oh wait i did no reviewing at all :laughing: let me do some fixes ZorbaTheGreatGreek 59 — 4y
Log in to vote
-1
Answered by 4 years ago
for _, v in pairs(Instance:GetChildren()) do -- Remember, v represents all the members of the table when using "in pairs()"
    if v:IsA("Script") then -- checks if the child is a script
        v.Disabled = true -- Disables the child
    end
end

Answer this question