Welding script failing

Hello!
I’m creating a welding script to weld tree parts together. I have a folder in the workspace with all of the trees I want to be welded. Here’s the script, I’m getting no errors, nothing prints and I’m not quite sure why. If you can help me out, it will be greatly appreciated!

for i,Parts in pairs(script.Parent:GetChildren()) do
	if Parts.ClassName == "Model" and Parts.Name == "smallTree" or "mediumTree" or "Tree" then
		for _,q in pairs(Parts:GetChildren()) do
			local x = q:GetChildren()
			for h = 1, #x do					
				local PrimaryPart = x.PrimaryPart
				if x[h]:IsA("BasePart") then
					print("found all baseparts")
					local weld = Instance.new('Weld', PrimaryPart)
					weld.Part0 = PrimaryPart
					weld.Part1 = x[h]
					weld.C0 = PrimaryPart.CFrame:Inverse()
					weld.C1 = x[h].CFrame:Inverse()
					print("Applied welds")
				end
			end
		end
	end
end

You need parenthesis around the or conditionals like this:

if Parts.ClassName == “Model” and (Parts.Name == “smallTree” or “mediumTree” or “Tree”) then

So that the in statement knows you want the first conditional and only 1 of the or conditionals to work properly. Since I don’t have your models, it could be hard to tell.

Unfortunately, still nothing, no prints or errors.

Here’s a picture of the trees folder.
https://gyazo.com/95d6def4e0b2fd3eb98065fd4bd239aa

The Weld script is the one that is supposed to weld all scripts. Also, all parts are un-anchored and CanCollide = false due to a TweenService effect I have when the trees health = 0.

I managed to get the prints to work for me, so I’m not sure what the issue is really. Did you manage to get some prints to work at least, otherwise we are having two different issues.

No prints, not sure what’s going on.

With this somewhat updated code, still getting nothing. Could you send me what you wrote? Maybe I just made a mistake somewhere. I’ve gone over it and can’t seem to find what I did wrong.

for i,Parts in pairs(script.Parent:GetChildren()) do
	if Parts.ClassName == "Model" and (Parts.Name == "smallTree" or "mediumTree" or "Tree") then
		for _,x in pairs(Parts:GetChildren()) do
			for h = 1, #x:GetChildren() do					
				local PrimaryPart = x.PrimaryPart
				if x[h]:IsA("BasePart") then
					print("found all baseparts")
					local weld = Instance.new('Weld', PrimaryPart)
					weld.Part0 = PrimaryPart
					weld.Part1 = x[h]
					weld.C0 = PrimaryPart.CFrame:Inverse()
					weld.C1 = x[h].CFrame:Inverse()
					print("Applied welds")
				end
			end
		end
	end
end

Sadly, I took exactly what you gave me, and put it into Studio, and I received print statements. Still trying to figure it out though.

I’m guessing you did, but did you check the screenshot I provided?

I did, and I even tried replicating the structure. I ended up getting errors, and print statements.

I mean, if I have to, I can just add scripts in each tree, I’m trying to avoid that at all costs. But, if that’s what I have to do then I can.

Sorry for the delay while I attempted the issue.

Is your script is ReplicatedStorage? More specifically, is the script in workspace or ServerScriptStorage? If it’s not in one of two of those places, the script will not work.

1 Like

The script is located in the trees folder which is in the workspace.

Have you tried placing a print statement before the loop begins? Maybe there is some type of issue with the script not working at all?