#Attempt to index nil

20 messages · Page 1 of 1 (latest)

wintry mulch
#

I get the error "Attempt to index nil with 'Backpack' " on this line. I'm using this code from a tutorial and have no idea what is wrong. It also doesn't print.

local function giveTool(player: Player, tool: string)
    local toolClone = ServerStorage:FindFirstChild("Tools"):FindFirstChild(tool):Clone()
    toolClone.Parent = player.Backpack
    print(toolClone.Parent.Name)
end
slender nacelle
#

@wintry mulch

wintry mulch
#

it printed nil

slender nacelle
#

show me where you are calling the function

#

give the entire script

wintry mulch
#

ok its inside of a datastore/leaderstats script that is different from the tutorial im watching but he put it in his datastore script so that might be why

woven pelicanBOT
#

studio** You are now Level 1! **studio

wintry mulch
#
game.Players.PlayerRemoving:Connect(function(player) -- When a player leaves
    local success, err  = pcall(function()
        saveData(player) -- Save the data
    end)

    if success then
        print("Data has been saved")
    else
        print("Data has not been saved!")
    end
end)

game:BindToClose(function() -- When the server shuts down
    for _, player in pairs(game.Players:GetPlayers()) do -- Loop through all the players
        local success, err  = pcall(function()
            saveData(player) -- Save the data
        end)

        if success then
            print("Data has been saved")
        else
            print("Data has not been saved!")
        end
    end
end)

local function giveTool(player: Player, tool: string)
    local toolClone = ServerStorage:FindFirstChild("Tools"):FindFirstChild(tool):Clone()
    toolClone.Parent = player.Backpack
    print(toolClone.Parent.Name)
end

giveTool(player, "WoodenSword")
#

says the first message didnt go through?

#

i had to put it in 2 parts

#

the first message wont send

#

im just probably going to watch his tutorial on datastores and see if that works

woven pelicanBOT
#

studio** You are now Level 43! **studio

boreal bobcat
#

Where does player come from here?

#

@wintry mulch

wintry mulch
#

idk that’s just what the tutorial i’m watching put and it worked for him

#

i could link it and timestamp if you want

wintry mulch