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.
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.
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
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.