So what I'm trying to do is make it so if two blocks touch when I run the game, they weld together I successfully got it however the welds aren't consistent, such as one side isn't welded to another. Also, every time they touch a non block they spit out error and it's a total mess. Here's what I have so far:
local block = script.Parent
block.Touched:connect(function(hit)
if hit.values.isblock == true then
local newWeld = Instance.new("Weld", script.Parent)
newWeld.Part0 = block
newWeld.Part1 = hit
else
print("hit is not a valid block")
end
end)
So I've read everyone's answers and there are ways that are cleaner however all of the parts don't weld like so: prntscr.com/iwsylp

3 comments
if (hit:IsA("Part") or hit:IsA("UnionOperation") or hit:IsA("MeshPart")) and (not (hit.Name == "Baseplate")) then
Yeah but I only want blocks that are the same to weld though.
maybe something else is breaking your weld, like moving one of the parts? use UgOsMiLy's suggestion to get rid of the error messages and perhaps setting the parent after setting the parts makes a difference.