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

How do you remove a tool when you press a TextButton?

So my problem is that I have a GUI.  When I press the Text button, the GUI won't remove the tool from the backpack of the player.  This script is in a Local Script. 

function Remove()
player = game.Players.LocalPlayer
tools = player.Backpack:getChildren()
function onClicked()
for i = 1, #tools do
if tools[i]:isA("tool") then 
tools[i]:remove()

end
end

script.Parent.Mouse1ButtonDown:connect(Remove)

3 answers

Well, first things first you should never put nomal text in a script, it will break it. Put a -- in front of it on line 1. Second, you don't need a function for your variables. You just have to state them above the function. Third, you're trying to call remove but you should be connecting onclicked. Try this

--So my problem is that I have a GUI.  When I press the Text button, the GUI won't remove the tool from the backpack of the player.  This script is in a Local Script. (I put this in a note so it won't break the script

player = game.Players.LocalPlayer
tools = player.Backpack:getChildren() --Moved variables outside function

function Remove()
for i = 1, #tools do
if tools[i]:IsA("tool") then 
tools[i]:Destroy() --Destroy is better than remove
end
end

script.Parent.Mouse1ButtonDown:connect(Remove)

First, like Yoshi said, :Destroy() is a better method than :remove() Second, capitalize "Tool" Third, in your connecting line, it is supposed to be MouseButton1Down, not Mouse1ButtonDown

I believe the issue is that you've put:

if tools[i]:IsA("tool") then

Tool needs to be capitalised:

if tools[i]:IsA("Tool") then

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