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

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

Asked by
Yeevivor4 155
9 years ago
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

Log in to vote
0
Answered by
yoshiegg6 176
9 years ago

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)

Ad
Log in to vote
0
Answered by 9 years ago

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

Log in to vote
-1
Answered by
iFlusters 355 Moderation Voter
9 years ago

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

Answer this question