Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Make this function unequip when equipped and vise versa?

So ive got an inventory script im using and this is the part that equips when you click on the sword icon, but idk how to make it equip if its uneqipped and unequip when its equipped. atm it just unequips then instantly equips, please help?

		for i,v in pairs(player.Backpack:GetChildren()) do
            Obj1 = Instance.new('ImageButton',script.Parent.Frame)
			Obj1.ZIndex = 10
            Obj1.Size = UDim2.new(0,40,0,40)
            Obj1.Position = UDim2.new(0,45*i-40,0,7)
            Obj1.BackgroundTransparency = 0
           	Obj1.Image = v.TextureId
			Obj1.MouseButton1Down:connect(function()
				player.Character.Humanoid:UnequipTools()
				player.Character.Humanoid:EquipTool(v)
			end)
		end

1 answer

✓ Accepted answer

Regardless of if a tool is equipped or not, you are calling ::UnequipTools() and ::EquipTool(v) every time, which is the problem. If you want to disable this for a tool that is already equipped then just add an 'if' statement to check if the tool is a child of Player.Character

This discussion is preserved as it was. New answers, comments, and votes are closed.