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

How can I use Datastores to save models?

Asked by 9 years ago

What I mean by Models is that in a game I'm working on, it requires to save a players three characters and all the base equipment they're using, e.g. the brick color, the mesh and the hats. It's like what happens in Vampire Hunters 2 or Apocalypse Rising when you load up a game.

1
The best thing to do is store the information into a table and datastore the table, IMO. Vlatkovski 320 — 9y

1 answer

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

Data Stores are not able to save Instances so you would therefore need to put all your data into a table or something like that and save it using that, here's an example:

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

game.Players.PlayerRemoving:connect(function(plr)
    local key = "user_"..plr.userId
    Stats:SetAsync(key, {goldKnife = true, goldGun = false})
end)

Then loading would be like this:

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

game.Players.PlayerAdded:connect(function(plr)
    local key = "user_"..plr.userId
    local stats = Stats:GetAsync(key)
    if stats and stats.goldKnife then
        game.ReplicatedStorage.Knife:Clone().Parent = plr.StarterGear
    end
end)
Ad

Answer this question