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

Can someone help me figure this out?

My sword keeps falling apart anything I play, I put all the parts in a handle, I know I am suppose weld everything but I didn't know how to make a Weld script, so if there is a easier way can you tell me or if you know how to make a weld script can you tell me?

1 answer

Weld scripts are quite tricky, I must admit that. It's a shame that ROBLOX does not provide this in their API.

You can integrate the CreateWelds function with your tool API. I provided some standard way of doing this.

local tool = script.Parent

-- user-defined code

function UpdateWeld(part1, part2, c1, c2) --c1 and c2 have to be provided, reading from part1/part2 fails sometimes. yes, strange.
	if part1:FindFirstChild("Weld") then
		part1.Weld:Destroy()
	end
	local Weld = Instance.new("Weld", part1)
	Weld.Name = "Weld"
	Weld.Part0 = part2
	Weld.Part1 = part1
	Weld.C0 = c2:toObjectSpace(c1)
end

function CreateWelds(tool)
	local weld_to = tool.Handle
	for i,v in pairs(tool:GetChildren()) do
		if v:IsA("BasePart") and v ~= weld_to then
			UpdateWeld(v, weld_to, v.CFrame,weld_to.CFrame)
		end
	end
end

--user-defined code

tool.Equipped:connect(function()
	CreateWelds(tool)
	-- user defined code
end)

2 comments

0

So does this go in the tool or the handle?. Also will all the parts not fall apart?

0

Into the tool. If everything goes right this should weld your tool so it doesn't fall apart.

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