local item = {} local plr = game.Players.LocalPlayer script.Parent.MouseButton1Click:Connect(function() if item == plr.Backpack:WaitForChild("craft") then script.Parent.Text = "putted!" item:Destroy() end end)
when i click a button it doesn't remove a tool and the text don't change. this was my own made script i tried to make my own so i can make a backpack gui as my own but i tried the first step but i have a hard time for it.
Explanation
Your script is basically correct, there is just a simple error that is confusing the local script
. You've made a table
for the item but you haven't defined what will be inside the table and you've implemented item:Destroy()
which is actually wrong. You have to implement what's inside the player's Backpack and then tell the script to destroy it..
Problem
local item = {} -- At line 1
item:Destroy() -- At line 6
Solution
The local script for removing the tool from player's backpack when clicking a button will be as follows;
local player = game.Players.LocalPlayer -- Define the variable for player script.Parent.MouseButton1Click:Connect(function() if player.Backpack:FindFirstChild("craft") then -- If statement to check script.Parent.Text = "putted" -- Changes the text of the button player.Backpack.craft:Destroy() -- Destroys the tool in player's backpack print("Craft has been destroyed from the player's backpack") -- Prints, you can delete this if you want.. end end)
Please make sure to up vote and select this as the answer if it helped you!