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

How can you make a duel wield weapon?

Asked by 8 years ago

I want to know how can you make the left arm raise up like the right arm when holding a weapon. I acknowledge that there is a child inside the right arm whenever you hold a tool up(Which is sorta like a weld). Just that how can I obtain that property and do the same. I know I can use the "Equipped" function, but my major concern is how to get "Weld". Please, Thank you.

2 answers

Log in to vote
1
Answered by 8 years ago

Here's how you do it (in concept, I haven't done it before, but it should work):


Step 1.

Inside tools, there should be a property called "RequiresHandle" (or something like that, I don't have access to the wiki at the moment). Find it and disable it. Create the parts for the tool, and put them in their own individual models inside the tool, like the following:

  • Tool
    • LeftSword
      • Handle
      • Part
    • RightSword
      • Handle
      • Part

For ease of use, set each of the models' PrimaryParts to their Handle.

Step 2.

Create a LocalScript inside the tool. Name it 'ToolHandler'. This won't work with FE if you're intending to do server stuff (like hurting other players), but I could help you with that if you need it. Change the script's code to this:

local tool = script.Parent
local ls = tool:WaitForChild("LeftSword") -- or your model's name
local rs = tool:WaitForChild("RightSword") -- or your other model's name
local lh = ls.PrimaryPart -- the left handle
local rh = rs.PrimaryPart -- the right handle
local p = game.Players.LocalPlayer
local char = p.Character
local la = char:WaitForChild("Left Arm")
local ra = char:WaitForChild("Right Arm")

function weld(h,obj) -- function for welding
    local w = Instance.new("Weld") -- new weld
    w.Part0 = h -- sets the first part
    w.Part1 = obj -- sets the second part
    local cf = CFrame.new(obj.Position) -- defines cframe for below
    w.C0 = h.CFrame:inverse() * cf -- makes it so this one and the one under keep their positions (welds move objects to the other's position)
    w.C1 = obj.CFrame:inverse() * cf
    w.Parent = obj -- sets the parent, it has to be done after above
    w.Name = h.Name.. "-" ..obj.Name.. "Weld" -- sets name
end

for _,v in pairs (ls:GetChildren()) do -- welds left sword
    if v ~= lh and v:IsA("BasePart") then -- checks to see if it is viable for welding
        weld(lh,v) -- welds
    elseif v == lh then
        weld(la,lh) -- welds handle to left arm, note that you will need to make an offset yourself, I do not have experience in this part, sorry
    end
end

for _,v in pairs (rs:GetChildren()) do -- welds right sword
    if v ~= rh and v:IsA("BasePart") then -- checks to see if it is viable for welding
        weld(rh,v) -- welds
    elseif v == rh then
        weld(ra,rh) -- welds handle to right arm, note that you will need to make an offset yourself, I do not have experience in this part, sorry
    end
end

That's hopefully all the code you will need. You should be able to make other things work now if you coded them. The swords should now be welded to the character and should disappear and reappear when equipped/unequipped. Tell me if this doesn't work, I'll try and help later :)

~TDP


TIP

You can use animations in tools easily, there is no need to animate with CFrame anymore!

0
Another great answer from TDP! UniversalDreams 205 — 8y
Ad
Log in to vote
-1
Answered by 8 years ago

As far as I know, there is no weld for the left arm. You will simply have to make the weld yourself and animate the tool by changing the C0 and C1 properties of that weld... Someone correct me if I am wrong about this

Answer this question