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

How do you weld 2 models with a script?

Asked by
Protune 15
9 years ago

What I want to do is that I can have Model1 in a game. Model1 can be anything (welded, not anchored)

Model2 is my model, and I want to be able to insert that model via admin commands.

How do I make it so that if I put Model2 somewhere on Model1 with a drag tool, it welds model2 to model1?

Thanks, Protune

1 answer

Log in to vote
0
Answered by
ZeroBits 142
9 years ago

This is an interesting question in that you want it to become welded via interaction with the Move Tool.

let's see if this works, we'll be using some code from this tutorial on the wiki; http://wiki.roblox.com/index.php?title=Welds#Welding_together_two_existing_bricks

I have no idea if this will work, as I don't know exactly how the move tool works.

local weldFrom = script.Parent -- set the part that will weld itself to the other one
local weldTo = 'NAME OF PART THAT IT CAN BE WELDED TO'

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

weldFrom.Touched:connect(function(hit) -- when a brick is touched with the other brick
    if hit.Name == weldTo then -- if it's the right brick
        weldBetween(weldFrom,hit ) -- weld them
    end
end)

Ad

Answer this question