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

Help here needed! welding a Gun? [Solved]

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

✓ Accepted answer

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()

5 comments

1

am not much of a Free Modeler :P

1

I edited my answer.

1

thnx a ton! no errors and is fine! :D thnx!

1

You're welcome, now you can uhh.. Change the title to [SOLVED.] K? ;)

1

yup... sry, I didnt get notifications of ur Comment

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