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

Wheres the error in this welding script?

Asked by 9 years ago

Hello scripting helpers, I am really confused with welding using scripts, here's an attempt I tried to make in ROBLOX studio.

function weld()
local human = workspace.Player:FindFirstChild("Humanoid")
local w = Instance.new('Weld', workspace)
w.Part0 = human.Head
w.Part1 = Instance.new('Part', workspace)
end
weld()

The output shows nothing, and I can't find the error on my code, also I have tried it with local and normal scripts.

1 answer

Log in to vote
1
Answered by 9 years ago

You can do this a bit easier so you don't have to find the relative values:

function Weld(x,y)
    local W = Instance.new("Weld")
    W.Part0 = x
    W.Part1 = y
    local CJ = CFrame.new(x.Position)
    local C0 = x.CFrame:inverse()*CJ
    local C1 = y.CFrame:inverse()*CJ
    W.C0 = C0
    W.C1 = C1
    W.Parent = x
end

function Get(A)
    if A.className == "Part" then
        Weld(script.Parent.Handle, A)
        A.Anchored = false
    else
        local C = A:GetChildren()
        for i=1, #C do
        Get(C[i])
        end
    end
end

function Finale()
    Get(script.Parent)
end

Finale()

if you want it in a tool, do this:

function Weld(x,y)
    local W = Instance.new("Weld")
    W.Part0 = x
    W.Part1 = y
    local CJ = CFrame.new(x.Position)
    local C0 = x.CFrame:inverse()*CJ
    local C1 = y.CFrame:inverse()*CJ
    W.C0 = C0
    W.C1 = C1
    W.Parent = x
end

function Get(A)
    if A.className == "Part" then
        Weld(script.Parent.Handle, A)
        A.Anchored = false
    else
        local C = A:GetChildren()
        for i=1, #C do
        Get(C[i])
        end
    end
end

function Finale()
    Get(script.Parent)
end

script.Parent.Equipped:connect(Finale)
script.Parent.Unequipped:connect(Finale)
Finale()
Ad

Answer this question