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

My game cant destroy() an item from StarterGear, but it can from Backpack?

Asked by 6 years ago

so i have a script that will find all tools in a players backpack. if they click the button it will sell that item and destroy the item from their backpack and StarterGear.

and player is set to local player = game.Players.LocalPlayer

    newslot.MouseButton1Click:connect(function() -- does this when clicked
        local lookforname = player.Backpack:FindFirstChild(tools[i].Name) -- looks for the tool name in backpack
        if lookforname then -- once it finds the tool it adds the sell value to the players gold
            player.leaderstats.Gold.Value = (player.leaderstats.Gold.Value) + (tools[i].sellPrice.Value)
            newslot:Destroy()
            local item2destroyfromBackpack = player.Backpack:FindFirstChild(tools[i].Name)
            item2destroyfromBackpack:Destroy()
            local item2destroyfromStarterGear = player.StarterGear:FindFirstChild(tools[i].Name)
            item2destroyfromStarterGear:Destroy()

it destroys the item from the backpack but then it says attempt to index local 'item2destroyfromStarterGear' (a nil value)

so once i respawn i still have that item which is not good.

thank you for any help!

0
Is it in a local script or a script? Ize_Cubz 18 — 6y
0
You don't need to remove the item from the StarterPack at all. As long as it's removed from the Backpack, they shouldn't be able to access it. ax_gold 360 — 6y
0
@ax_gold the problem is, i need to remove the item from their StarterPack because i dont want them to respawn with that item after they sell it. PoePoeCannon 519 — 6y
0
Maybe [i] is nil, or the script can’t find the tools you’re looking for. You should use conditional statements in case something like that happens. User#20279 0 — 6y

Answer this question