Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make a weld for each side using a script?

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. Here's what I have so far:

local block = script.Parent
block.Touched:connect(function(hit)
	if hit:FindFirstChild("values") and hit.values:FindFirstChild("isabrick") == true then
		local newWeld = Instance.new("Weld")
		newWeld.Part0 = block
		newWeld.Part1 = hit
		newWeld.Parent = script.Parent
	else
		print("hit is not a valid block")
	end
end)

Some sides don't weld to other blocks like so:

prntscr.com/iwsylp

1 answer

The last time I saw one of your questions, I answered it with pleasure. Making a Weld instance is relatively easy; you just have to put it in the JointsService and not the Workspace. Here is a script that should work:

block = script.Parent
block2 = script.Parent.Parent.Block2 -- This assumes that the part is in the workspace, but you can name this whatever you want, as long as it is another part or side
function Weld()
	local weld = Instance.new("Weld", game.JointsService)
	weld.Part0 = block
	weld.Part1 = block2
	weld.C1 = block2.CFrame:toObjectSpace(block.CFrame)
end
Weld()

Not only will it weld, it will also maintain the weld as long as the group of parts being welded is not regenerated.

This discussion is preserved as it was. New answers, comments, and votes are closed.