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

Help here needed! welding a Gun? [Solved]

Asked by
KAAK82 16
10 years ago
function Weldnow()
local w1 = Instance.new("Weld")
w1.Parent = script.Parent.Handle
w1.Part0 = w1.Parent
w1.Part1 = script.Parent.Barrel
end

script.Parent.Equipped:connect(Weldnow)
script.Parent.Unequipped:connect(Weldnow)

this is my Script, it keeps pulling the Pieces together! so the Bullet shoots Down... plz help me here, how would I weld them without them being in the same Position?

Edit: tried this

function weldBetween(a, b)
    local weld = Instance.new("ManualWeld")
    weld.Part0 = script.Parent.Handle
    weld.Part1 = script.Parent.Barrel
    weld.C0 = CFrame.new()
    weld.C1 = b.CFrame:inverse() * a.CFrame
    weld.Parent = a
    return weld;
end
weldBetween(script.Parent.Handle, script.Parent.Barrel)

script.Parent.Equipped:connect(weldBetween)
script.Parent.Unequipped:connect(weldBetween)

and this

function weldBetween(a, b)
    local weld = Instance.new("ManualWeld")
    weld.Part0 = a
    weld.Part1 = b
    weld.C0 = CFrame.new()
    weld.C1 = b.CFrame:inverse() * a.CFrame
    weld.Parent = a
    return weld;
end
weldBetween(script.Parent.Handle, script.Parent.Barrel)

script.Parent.Equipped:connect(weldBetween)
script.Parent.Unequipped:connect(weldBetween)

but for these 2 it did fine, but except, it says either b is a nil Value or something else... sry I forgot about the other Error... this Stupid Output doesn't sho me the Old Errors for some Reason...

1 answer

Log in to vote
1
Answered by 10 years ago

Put this in a LocalScript

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()
1
am not much of a Free Modeler :P KAAK82 16 — 10y
1
I edited my answer. Grenaderade 525 — 10y
1
thnx a ton! no errors and is fine! :D thnx! KAAK82 16 — 10y
1
You're welcome, now you can uhh.. Change the title to [SOLVED.] K? ;) Grenaderade 525 — 10y
1
yup... sry, I didnt get notifications of ur Comment KAAK82 16 — 10y
Ad

Answer this question