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

when i click a button it doesn't remove a tool and the text don't change why?

Asked by
lo_1003 42
4 years ago
Edited 4 years ago
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.

0
Is this a local script? SilentsReplacement 468 — 4y
0
Yeah lo_1003 42 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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!

0
I tried to fix my own but man you saved me! thanks! lo_1003 42 — 4y
Ad

Answer this question