Hello, I’m trying to make a script that goes through a model, checks if there are Models inside of the mode, and then checks their name so it can change CanCollide. When I run it I get no errors, but it doesn’t work. I’m making this because I have a huge model with tons of Trees inside of it, and when I tried ungrouping it my Studio crashed, so I’m making a script for it. I just don’t understand why it’s not working.
function collideOff()
local Trees = script.Parent:GetChildren()
for i = 1, #Trees do
local child = Trees[i]
if child:IsA("Model") then
local Log = child:GetChildren()
if Log.Name == "Log" or "MeshPart" then
Log.CanCollide = false
end
end
end
end
wait()
collideOff()
local function CollideOff()
for _,Children in pairs(script.Parent:GetChildren()) do
for _,Child in pairs(Children:GetChildren()) do
if Child:IsA("Model") then
for _,Log in pairs(child:GetChildren()) do
if Log.Name == "Log" or "MeshPart" then
Log.CanCollide = false
end
end
end
end
end
end
wait()
CollideOff()
function CollideOff()
for _, Child in pairs(script.Parent:GetChildren()) do
if Child:IsA("Model") then
for _, Descendant in pairs(Child:GetDescendants()) do
if (Descendant.Name == "Log" or "MeshPart") and (Descendant:IsA("BasePart")) then
Descendant.CanCollide = false
end
end
end
end
end
wait()
CollideOff()
This is assuming that you don’t really need to care about any other models inside Trees.Model, it’ll just go through and check the name, then make sure it isn’t a model or other.