Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can someone help me figure this out?

Asked by
red106 0
10 years ago

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

Log in to vote
0
Answered by
jobro13 980 Moderation Voter
10 years ago

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)
0
So does this go in the tool or the handle?. Also will all the parts not fall apart? red106 0 — 10y
0
Into the tool. If everything goes right this should weld your tool so it doesn't fall apart. jobro13 980 — 10y
Ad

Answer this question