function Create(t)return function(U)local D=Instance.new(t)for t,U in pairs(U)do if type(t)=="\110\117\109\098\101\114"then U.Parent=D else D[t]=U end end return D end end local t=script.Parent.Parent local U=nil local D=nil local j=0 t.Equipped:connect(function()j=j+1 local U=j local u=game.Players:GetPlayerFromCharacter(t.Parent)local L=u.Character local T=L:FindFirstChild("\082\105\103\104\116 \065\114\109")if T and T:FindFirstChild("\082\105\103\104\116\071\114\105\112")then local U=T.RightGrip local j=U.Part1 local u=T.ChildRemoved:connect(function(u)if u==U then D:Remove()D=nil if j and L:FindFirstChild("\084\111\114\115\111")then if t.Parent.Parent:IsA("\080\108\097\121\101\114")then j.CFrame=CFrame.new(100000,100000,100000)else j.CFrame=L.Torso.CFrame*CFrame.new(0,0,-(j.Size.magnitude+2))end end end end)D=(Create("\077\111\116\111\114\054\068"))({Name="\082\105\103\104\116\071\114\105\112\095\077\111\116\111\114",Part0=T,Part1=j;C0=CFrame.new(0,-1,0,1,0,0,0,0,1,0,-1,0),C1=CFrame.new(.1,-0.6,.4,1,0,0,0,0,-1,0,1,0)})U.Part1=nil U.Part0=nil D.Parent=U.Parent end end)t.Unequipped:connect(function()j=j+1 if U then U:disconnect()U=nil end end)
-- stravant's AnimEdit helper, to make sure tools actually animate.

function Create(ty)
	return function(data)
		local obj = Instance.new(ty)
		for k, v in pairs(data) do
			if type(k) == "number" then
				v.Parent = obj
			else
				obj[k] = v
			end
		end
		return obj
	end
end

local Tool = script.Parent.Parent

local armChildRemovedConn = nil
local Motor6DGrip = nil
local EquippedNum = 0

Tool.Equipped:connect(function()
	EquippedNum = EquippedNum + 1
	local myEquip = EquippedNum
	--some vars
	local Player = game.Players:GetPlayerFromCharacter(Tool.Parent)
	local Character = Player.Character

	local rightarm = Character:FindFirstChild("Right Arm")
	if rightarm and rightarm:FindFirstChild("RightGrip") then
		local rightGrip = rightarm["RightGrip"]
		local handle = rightGrip.Part1

		--kill my joint when the normal joint is removed
		--this must be done here so that the joint is removed
		--_right away_ after unequipping and the character doesn't
		--glitch up.
		local armChildRemovedConn = rightarm.ChildRemoved:connect(function(ch)
			if ch == rightGrip then
				Motor6DGrip:Remove()
				Motor6DGrip = nil
				--
				if handle and Character:FindFirstChild("Torso") then
					if Tool.Parent.Parent:IsA("Player") then
						--the sword has been deselected
						--put the sword far away so the user doesn't notice that the handle doesn't
						--update for about 0.1 seconds after selecting the tool.
						handle.CFrame = CFrame.new(100000, 100000, 100000)
					else
						--if in the workspace, position the handle where it should be dropped
						--use the size of the handle to make sure it's dropped far enough away
						handle.CFrame = Character.Torso.CFrame * CFrame.new(0, 0, -(handle.Size.magnitude + 2))
					end
				end
			end
		end)

		--make my new joint
		Motor6DGrip = Create("Motor6D")({
			Name = "RightGrip_Motor",
			Part0 = rightarm,
			Part1 = handle,
			C0 = CFrame.new(0, -1, 0, 1, 0, -0, 0, 0, 1, 0, -1, -0), -- from original right grip
			C1 = CFrame.new(0.1, -0.6, 0.4, 1, 0, 0, 0, 0, -1, 0, 1, 0),
		})
		--kill the old weld
		rightGrip.Part1 = nil
		rightGrip.Part0 = nil
		Motor6DGrip.Parent = rightGrip.Parent
	end
end)

Tool.Unequipped:connect(function()
	EquippedNum = EquippedNum + 1
	if armChildRemovedConn then
		armChildRemovedConn:disconnect()
		armChildRemovedConn = nil
	end
end)
