Welding Weapon Problem

I have a weapon system that I’m trying to make work, and it works besides one problem. I don’t know where to place the part called “hilt”. The code for it is:

Code

tool.Equipped:Connect(function()

local w = Instance.new(‘Weld’)

w.Part0 = script.Parent.Parent:WaitForChild(‘hilt’)

w.Part1 = handle1

w.Parent = handle1

w.C0 = tool.offset.Value

end)

This is the layout for the tool:

Layout

image

Where should I put the part called “hilt”?

I believe you already have a hilt in your model which is the handle so you should just be able to set the Weld.Part0 to script.Parent.Parent:WaitForChild("handle") instead of script.Parent.Parent:WaitForChild("hilt"). (A hilt is a handle for swords)

I tried that and it took away the error, but my character still doesn’t hold it properly. It says “script.Parent.Parent:WaitForChild(“hilt”)” which would lead to a hilt in the StarterPack but I tried and it didn’t work.

Rename the hilt to “Handle” and let me know if that works. (remember to replace the WaitForChild call argument with the new name too)

local tool = script.Parent
local handle1 = tool:WaitForChild(‘handle’)
local tm1 = tool:WaitForChild(‘toolModel’)

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

for _,v in next,tm1:GetChildren() do
if v:IsA(‘BasePart’) then
weld(handle1,v)
end
end

weld(handle1,tool:WaitForChild(‘Barrel’))

tool.Equipped:Connect(function()
local w = Instance.new(‘Weld’)
w.Part0 = script.Parent.Parent:WaitForChild(‘hilt’)
w.Part1 = handle1
w.Parent = handle1
w.C0 = tool.offset.Value
end)

This is the full code if that helps, but I already tried renaming it and it didn’t work.