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
9 years ago

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

01t = script.Parent --Toolbar GUI, first slot
02tool = script.Parent.ToolFolder.Tool --The assigned tool
03player = game.Players.LocalPlayer --The player equipping and unequipping
04equipped = false --Becomes true when the tool is equipped to signify that it is equipped
05 
06function EquipTool() --For equipping the tool
07    player.Humanoid:EquipTool(tool) --Code to equip the assigned tool
08end
09 
10function UnequipTool() --For unequipping the tool
11    ???
12end
13 
14t.MouseButton1Up:connect(function() --Click the GUI to equip or unequip
15    if equipped == false then
View all 22 lines...

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
9 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.

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

Let me know if there is any errors.

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

Answer this question