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

trouble with script that welds all parts in workspace to other touching parts, any ideas?

Asked by
BRAEGON -8
5 years ago

So I'm making a round based survival game with terrain and I'm trying to find a way to weld all parts that are touching to each other on command and so far i have made this script. I need some sort of code that does this or else I will have to make a line of code for every weld that needs to be made, and with hundreds of parts, this would be incredibly time-consuming. Honestly even just knowing whether or not Roblox can support this would be really helpful

local function weldBetween(a, b)
        --Make a new Weld and Parent it to a.
        local weld = Instance.new("ManualWeld", a)
        --Get the CFrame of b relative to a.
        weld.C0 = a.CFrame:inverse() * b.CFrame
        --Set the Part0 and Part1 properties respectively
        weld.Part0 = a
        weld.Part1 = b
        --Return the reference to the weld so that you can change it later.
        return weld
    end





    for _,part in pairs(game.Workspace:GetDescendants()) do
       if part:IsA("Part") then     ---- or part:IsA("MeshPart")
            for _,touching in pairs(part:GetTouchingParts()) do
                --weld(part,touching)
                local weldOne = weldBetween(part, touching)
            end
        end
    end

1 answer

Log in to vote
0
Answered by 5 years ago

You could put all the items you want welding together into a model, in workspace, and just change line #17 to fit it.

Otherwise you can use CollectionService to get specific items in which have a 'tag' attached to them.

Ad

Answer this question