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

Help with saving tools?

Asked by 8 years ago
datastore = game:GetService("DataStoreService"):GetDataStore("ToolStore")

game.Players.PlayerRemoving:connect(function(player)
    local stats = {}
    local e = 0
    for i,v in pairs(player.Backpack:GetChildren()) do
        e=e+1
        table.insert(stats,e,v.Name)
    end
    datastore:SetAsync('Tool thing#'..player.userId,stats)
end)

game.Players.PlayerAdded:connect(function(player2)
    local store = datastore:GetAsync('Tool thing#'..player2.userId)
    if store then
        for q=1,#store do
            game.ReplicatedStorage:FindFirstChild(store[q]).Parent = player2.Backpack
        end
    end
end)

line 17, attempt to index a nil value.

That error stumps me, a copy of all the tools in the game are inside of replicated storage, so I don't see what's wrong with this.

0
I did... ScriptsAhoy 202 — 8y

1 answer

Log in to vote
0
Answered by
robocu3 30
8 years ago

Beings I don't have enough rep to comment, I guess I have to stretch this out to an answer. game.ReplicatedStorage:FindFirstChild(store[q]) must not be returning anything. I also have to comment on some unorthodox things you're doing, albeit valid... why have variable e? Why increment it instead of just using table.insert? Pos isn't a mandatory param., it can be omitted and you'd get the same result with some cleaner looking code :P also curious as to why you used pairs on line 6 but a numeric for on line 16(though numeric is arguably more efficient, it's not uniform in this scenario) These are just nitpicks, though, for the sake of improvement(not that you were seeking critique), they shouldn't be causing an error. If you could print store[q] and see what it is, it'd probably help you narrow down the problem. Comment on this with results and I'll see if I can help you further.

Ad

Answer this question