Why won't this script change the Collisions of Parts?

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()
2 Likes

It’s because you’re trying to get the name of a table. Use a for i, v in pairs loop or use a for loop to loop through the Log.

You can do this i think

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()

When I use this it says
‘Attempting to index nil with :IsA’

I edited it, capital error (i dont know if that broke it)

Still get an error
CanCollide is not a valid member of Model “Workspace.Trees.Model.Model.Tree”

Give me a screenshot of the Explorer

image
I can’t post the entire thing since it’s too big, but underneath the Model are the Tree models

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.