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

Why do my weapons break whenever I equip them?

Asked by 8 years ago

I'm trying to create two weapons, both with a handle on it. So to be clear, I am making a single tool that has two weapons in it. I just cannot get it to work no matter what. I have tried welding the whole thing together and I've also tried to weld just the two weapons by themselves if that makes any sense. All I can say is that I have had no success with making these weapons go by my hands. The only thing that happens is the weapon goes into my right hand and that's it, but I don't want that to happen, i want one weapon in one hand and one weapon in the other hand. Please tell me what I am doing wrong.

If I put this code in a local script in the weapon, the handle goes in my hand... but literally nothing else, not even the other handle. I have named them correctly, handle and handle1.

01player = game.Players.LocalPlayer
02character = player.Character
03LArm=script.Parent.Parent:WaitForChild("Left Arm")
04RArm=script.Parent.Parent:WaitForChild("Right Arm")
05function KaiWeld()
06        local w1 = Instance.new("Weld")
07        w1.Parent = script.Parent.Handle
08        w1.Part0 = w1.Parent
09        w1.Part1 = script.Parent.Handle-------- This is the weapon that goes in the character's Right hand
10        w1.C1 = CFrame.fromEulerAnglesXYZ(1, 0, 0) * CFrame.new(RArm.Position.CFrame.new(0,0,0),0,0)
11 
12 
13        local w2 = Instance.new("Weld")
14        w2.Parent = script.Parent.Handle
15        w2.Part0 = w2.Parent
16        w2.Part1 = script.Parent.Handle1-------- This is the weapon that goes in the Character's Left hand
17        w2.C1 = CFrame.fromEulerAnglesXYZ(0, 0, 0) * CFrame.new(LArm.Position.CFrame.new(0,0,0),0,0)
18end
19script.Parent.Equipped:connect(KaiWeld)
20script.Parent.Unequipped:connect(KaiWeld)

I also have this piece of code which basically keeps the weapon together. Without this, the weapon just falls apart and breaks. I don't know why, but this script won't let me choose the position of the handles and I want to be able to choose the position of EACH handle.

01function weld()
02    local parts,last = {}
03    local function scan(parent)
04        for _,v in pairs(parent:GetChildren()) do
05            if (v:IsA("BasePart")) then
06                if (last) then
07                    local w = Instance.new("Weld")
08                    w.Name = ("%s_Weld"):format(v.Name)
09                    w.Part0,w.Part1 = last,v
10                    w.C0 = last.CFrame:inverse()
11                    w.C1 = v.CFrame:inverse()
12                    w.Parent = last
13                end
14                last = v
15                table.insert(parts,v)
View all 27 lines...

1 answer

Log in to vote
0
Answered by 7 years ago

That should work. Just be sure that the script is in the weapon.

01tool = script.Parent
02handle = tool:WaitForChild("Handle")
03Types = {"Part","WedgePart","TrussPart"}
04 
05function Weld(obj)
06    local w1 = Instance.new("Weld",handle)
07    w1.Part0 = handle
08    w1.Part1 = obj
09    w1.C0 = handle.CFrame:inverse()
10    w1.C1 = obj.CFrame:inverse()
11 
12    obj.Anchored = false
13end
14 
15function Confirming()
View all 28 lines...
Ad

Answer this question