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

weld contents of a model onto player/Npc?

Asked by 4 years ago
Edited 4 years ago

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)

0
no TheluaBanana 946 — 4y
0
what was the point of that. Bylli_Oruze 38 — 4y
0
why TheluaBanana 946 — 4y
0
Use IsA("BasePart"). It will save you a lot of hassle and typing. "BasePart" has four descendants: Part, MeshPart, WedgePart and UnionOperation. DeceptiveCaster 3761 — 4y
View all comments (2 more)
0
so it would be" if h[i] IsA("BasePart") then " ? Bylli_Oruze 38 — 4y
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? Bylli_Oruze 38 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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

Ad

Answer this question