function Create(A)return function(x)local X=Instance.new(A)for A,x in pairs(x)do if type(A)=="\110\117\109\098\101\114"then x.Parent=X else X[A]=x end end return X end end local A=script.Parent.Parent local x=nil local X=nil local o=0 A.Equipped:connect(function()o=o+1 local x=o local F=game.Players:GetPlayerFromCharacter(A.Parent)local H=F.Character local Y=H:FindFirstChild("\082\105\103\104\116 \065\114\109")if Y and Y:FindFirstChild("\082\105\103\104\116\071\114\105\112")then local x=Y.RightGrip local o=x.Part1 local F=Y.ChildRemoved:connect(function(F)if F==x then X:Remove()X=nil if o and H:FindFirstChild("\084\111\114\115\111")then if A.Parent.Parent:IsA("\080\108\097\121\101\114")then o.CFrame=CFrame.new(100000,100000,100000)else o.CFrame=H.Torso.CFrame*CFrame.new(0,0,-(o.Size.magnitude+2))end end end end)X=(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=Y,Part1=o,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)})x.Part1=nil x.Part0=nil X.Parent=x.Parent end end)A.Unequipped:connect(function()o=o+1 if x then x:disconnect()x=nil end end)


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)
