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

How can I get a player to equip and unequip a weapon through a GUI toolbar?

Asked by
8391ice 91
8 years ago

**This is an excerpt from the script of one of my toolbar slots

t = script.Parent --Toolbar GUI, first slot
tool = script.Parent.ToolFolder.Tool --The assigned tool
player = game.Players.LocalPlayer --The player equipping and unequipping
equipped = false --Becomes true when the tool is equipped to signify that it is equipped

function EquipTool() --For equipping the tool
    player.Humanoid:EquipTool(tool) --Code to equip the assigned tool
end

function UnequipTool() --For unequipping the tool
    ???
end

t.MouseButton1Up:connect(function() --Click the GUI to equip or unequip
    if equipped == false then
        EquipTool() --Equip tool
        equipped = true
    elseif equipped == true then
        UnequipTool() --Unequip tool
        equipped = false
    end
end)

The problem is that I do not know what code to put for the UnequipTool function; there is a built-in function for equipping a tool, which is EquipTool(), but there isn't one for unequipping a tool. How would I make this happen?

1 answer

Log in to vote
0
Answered by
Sublimus 992 Moderation Voter
8 years ago

When a player equips a conventional tool (not a hopperbin), the tool is parented to their character from their backpack. In this respect, if you were to transport the tool back to the backpack, it would be unequipped per-say.

function UnequipTool() --For unequipping the tool
    tool.Parent = player.Backpack
end

Let me know if there is any errors.

0
Thank you very much! It worked! ^.^ 8391ice 91 — 8y
Ad

Answer this question