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

game finds nil in player StarterGear?

Asked by 6 years ago
Edited 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!

Answer this question