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

weld contents of a model onto player/Npc?

i use an R15 morph to create my characters, but how would i rewrite this script so that instead of just welding single parts, it welds parts inside of a model too? (i already asked this question but i didnt get the answer i needed)

script:

function onTouched(hit)
    if hit.Parent:findFirstChild("Humanoid") ~= nil and hit.Parent:findFirstChild("Chest1") == nil then
        local g = script.Parent.Parent.Chest1:clone()
        g.Parent = hit.Parent
        local C = g:GetChildren()
        for i=1, #C do
            if C[i].className == "Part" or C[i].className == "UnionOperation" or C[i].className == "WedgePart" or C[i].className == "MeshPart" then
                local W = Instance.new("Weld")
                W.Part0 = g.Middle
                W.Part1 = C[i]
                local CJ = CFrame.new(g.Middle.Position)
                local C0 = g.Middle.CFrame:inverse()*CJ
                local C1 = C[i].CFrame:inverse()*CJ
                W.C0 = C0
                W.C1 = C1
                W.Parent = g.Middle
            end
                local Y = Instance.new("Weld")
                Y.Part0 = hit.Parent.UpperTorso
                Y.Part1 = g.Middle
                Y.C0 = CFrame.new(0, 0, 0)
                Y.Parent = Y.Part0
        end

        local h = g:GetChildren()
        for i = 1, # h do
            if h[i].className == "Part" or C[i].className == "UnionOperation" or C[i].className == "WedgePart" or C[i].className == "MeshPart" then
                h[i].Anchored = false
                h[i].CanCollide = false
            end
        end

    end
end

script.Parent.Touched:connect(onTouched)

6 comments

0

no

0

what was the point of that.

0

why

0

Use IsA("BasePart"). It will save you a lot of hassle and typing. "BasePart" has four descendants: Part, MeshPart, WedgePart and UnionOperation.

0

so it would be" if h[i] IsA("BasePart") then " ?

0

and plus how would i solve my problem? in the morph you have chest1, chest2, Hair, etc., the morph script welds the parts inside of these models, but how would i get the script to weld parts inside of a model inside of one of those models?

1 answer

after losing some hair and teeth, i got this:

function onTouched(hit)
	if hit.Parent:findFirstChild("Humanoid") ~= nil and hit.Parent:findFirstChild("Chest1") == nil then
		local g = script.Parent.Parent.Chest1:clone()
		g.Parent = hit.Parent
		local C = g:GetDescendants()
		for i=1, #C do
			if C[i]: IsA("BasePart") then
				local W = Instance.new("Weld")
				W.Part0 = g.Middle
				W.Part1 = C[i]
				local CJ = CFrame.new(g.Middle.Position)
				local C0 = g.Middle.CFrame:inverse()*CJ
				local C1 = C[i].CFrame:inverse()*CJ
				W.C0 = C0
				W.C1 = C1
				W.Parent = g.Middle
			end
				local Y = Instance.new("Weld")
				Y.Part0 = hit.Parent.UpperTorso
				Y.Part1 = g.Middle
				Y.C0 = CFrame.new(0, 0, 0)
				Y.Parent = Y.Part0
		end

		local h = g:GetDescendants()
		for i = 1, # h do
			if h[i]: IsA("BasePart") then
				h[i].Anchored = false
				h[i].CanCollide = false
			end
		end
		
	end
end

script.Parent.Touched:connect(onTouched)

thanks RobloxWhizYT for the Basepart bit

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