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

Is there a way to Weld Models?

Is there a way to weld models? I tried to but it puts in the output that CFrame is not a valid member of Model" or something. Here is the code:

function weldToHuman(a,b)
    b.CFrame = a.CFrame
    local  weld = Instance.new("Weld")
    weld.Part0 = a;
    weld.C0 = a.CFrame:inverse()
    weld.Part1 = b;
    weld.C1 = b.CFrame:inverse()
    weld.Parent = a;    
    return weld;
end
game.Players.PlayerAdded:connect(function(player)
    print(player.Name .. " Welcome");
    player.CharacterAdded:connect(function(character)
		game.Lighting.JetPack:Clone()
		game.Lighting.JetPack.Parent = game.Workspace
        print(character.Name .. "  character")
        wait(2);
        weldToHuman(character.Torso,game.Workspace.JetPack)
    end)
end)
print("loaded welding")

1 answer

Models cannot be welded. Instead, you can weld a part of the model, assuming that JetPack is the model you're trying to weld.

function weldToHuman(a,b)
    b.CFrame = a.CFrame
    local  weld = Instance.new("Weld")
    weld.Part0 = a;
    weld.C0 = a.CFrame:inverse()
    weld.Part1 = b;
    weld.C1 = b.CFrame:inverse()
    weld.Parent = a;    
    return weld;
end
game.Players.PlayerAdded:connect(function(player)
    print(player.Name .. " Welcome");
    player.CharacterAdded:connect(function(character)
        game.Lighting.JetPack:Clone()
        game.Lighting.JetPack.Parent = game.Workspace
        print(character.Name .. "  character")
        wait(2);
        weldToHuman(character.Torso,game.Workspace.JetPack.MainPart) -- Or whatever part is connected to the torso
    end)
end)
print("loaded welding")

Weld script:

model = script.Parent
for i,v in pairs(model:GetChildren()) do
	if v:IsA("Part") then
		w = Instance.new("Weld",v)
		w.Part0 = v
		w.Part1 = model.MainPart -- Or whatever you want the weld to attach to
		w.C0 = v.CFrame:inverse()
		w.C1 = model.MainPart.CFrame:inverse()
		wait()
	end
end

If you run this inside the jet pack model, it should weld all the parts together. Let me know if it doesn't work.

6 comments

0

Doesn't work. It only welds the part I told it to weld. The rest of the model just sits there.

0

It will work if you weld all the parts together.

0

I assumed that you had already done that, since you were trying to weld multiple parts to something else.

0

Yea I tried to weld all of it but it only does the first part i told it to.

0

I suggest that you use a weld script to do that for you inside of the jet pack and then run the script. It makes it a lot quicker.

0

Would you be able to get it for me? I am confused

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