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

Can Someone Help with DataStore Script?

Asked by 9 years ago

I'm trying to make a script that uses a script that saves the player's inventory if they leave the game. Here's what I have so far:

local ds = game:GetService("DataStoreService"):GetDataStore("tools")

game.Players.PlayerAdded:connect(function(player)
    local key = "user_" .. player.userId
    ds:UpdateAsync(key, function(old)
        old = game.Players.LocalPlayer.Backpack:GetChildren()
        if old:IsA("Tool") then
        local new = old or nil
        local tool = old:Clone()
        tool.Parent = game.Players.LocalPlayer.Backpack
        return new
        end
    end)

end)

I copied some of it from the wikia. I think I'm doing it all wrong. Please help!

0
You cannot save instances with datastore you can only save values and tables, those sort of things. Ryzox 220 — 9y

1 answer

Log in to vote
0
Answered by
Ryzox 220 Moderation Voter
9 years ago

I suggest looking over http://wiki.roblox.com/index.php?title=Data_store again and reading it properly. To do this I would make a tablewith item names in it and then you use those to access ReplicatedStorageand clone the tools into their Backpack.

Ad

Answer this question