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

Make this function unequip when equipped and vise versa?

Asked by
nicros 165
8 years ago

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

Log in to vote
1
Answered by 8 years ago

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

Ad

Answer this question