I have a tool that when a key is pressed, another “tool” (or part) appears in their other hand with that hand raised. I have been unable to optimize this for quite a while now. Currently, I just set the part/tool as a part of the main tool, and set its transparency while also playing an animation to make it look like they’re holding it in their off-hand.
Can someone help me optimize this so that I don’t have to add the part/tool into each versions of the main tool? I am aware it works fine, but I want to optimize how it functions.
local tool = script.Parent
tool.Activated:Connect(function()
local char = tool.Parent
local LeftArm = char["Left Arm"]
local RightArm = char["Right Arm"]
local Motor6D = Instance.new("Motor6D")
Motor6D.Name = "LeftGrip"
Motor6D.Parent = LeftArm
Motor6D.Part0 = LeftArm
Motor6D.Part1 = tool.Handle
local RightGrip = RightArm:FindFirstChild("RightGrip")
if RightGrip then
RightGrip:Destroy()
end
end)
UP
This script takes the sword and welds it to the left arm instead of the right arm.
Double Sword Script
local tool = script.Parent
local SecondSword = game.ReplicatedStorage.SecondSword:Clone()
tool.Activated:Connect(function()
local SecondSwordClone = SecondSword:Clone()
SecondSwordClone.Parent = tool
local char = tool.Parent
local LeftArm = char["Left Arm"]
local RightArm = char["Right Arm"]
local Motor6D = Instance.new("Motor6D")
Motor6D.Name = "LeftGrip"
Motor6D.Parent = LeftArm
Motor6D.Part0 = LeftArm
Motor6D.Part1 = SecondSwordClone
end)
This script clones a part called DoubleSword thats in replicatedstorage and welds it to the left arm
local tool = script.Parent
local SecondSword = game.ReplicatedStorage.SecondSword:Clone()
local double = false
local SecondSwordClone = nil
tool.Activated:Connect(function()
local char = tool.Parent
local LeftArm = char["Left Arm"]
local RightArm = char["Right Arm"]
if double then
double = false
if SecondSwordClone then
SecondSwordClone:Destroy()
SecondSwordClone = nil
end
local LeftGrip = LeftArm:FindFirstChild("LeftGrip")
if LeftGrip then
LeftGrip:Destroy()
end
else
double = true
SecondSwordClone = SecondSword:Clone()
SecondSwordClone.Parent = tool
local Motor6D = Instance.new("Motor6D")
Motor6D.Name = "LeftGrip"
Motor6D.Parent = LeftArm
Motor6D.Part0 = LeftArm
Motor6D.Part1 = SecondSwordClone
end
end)
Left Arm Sword
local tool = script.Parent
local RightHand = true
tool.Activated:Connect(function()
local char = tool.Parent
local LeftArm = char["Left Arm"]
local RightArm = char["Right Arm"]
if RightHand then
RightHand = false
local Motor6D = Instance.new("Motor6D")
Motor6D.Name = "LeftGrip"
Motor6D.Parent = LeftArm
Motor6D.Part0 = LeftArm
Motor6D.Part1 = tool.Handle
local RightGrip = RightArm:FindFirstChild("RightGrip")
if RightGrip then
RightGrip:Destroy()
end
else
RightHand = true
local Motor6D = Instance.new("Motor6D")
Motor6D.Name = "RightGrip"
Motor6D.Parent = RightArm
Motor6D.Part0 = RightArm
Motor6D.Part1 = tool.Handle
local LeftGrip = LeftArm:FindFirstChild("LeftGrip")
if LeftGrip then
LeftGrip:Destroy()
end
end
end)