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

How can I make a game save players progress?

Asked by 8 years ago

How could I save someone's progress including their look if I already have a default look for new players that is given on join? I'm just wondering how this could possibly be done. I don't want to be requesting anything.

0
DataStoreService? ISellCows 2 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

Check out the wiki page for DataStoreService, http://wiki.roblox.com/index.php?title=API:Class/DataStoreService.

This script isn't efficient, but it's an example of how you would use the service to do this.

local datastore = game:GetService("DataStoreService"):GetDataStore("StoreName")


game.Players.PlayerAdded:connect(function(player)
    repeat wait() until player.Character
    local character = player.Character

    if character:FindFirstChild("Shirt") then
         shirt = character.Shirt.ShirtTemplate
    end

    if character:FindFirstChild("Pants") then
         pants = character.Pants.PantsTemplate
    end

    if character:FindFirstChild("ShirtGraphic") then
         shirtg = character.ShirtGraphic.Graphic
    end     

    local key = "user-" .. player.userId

    local storeditems = datastore:GetAsync(key)

    if storeditems then
        shirt = storeditems[1]
        pants = storeditems[2]
        shirtg = storeditems[3]
    else
        local items = {shirt, pants, shirtg}
        datastore:SetAsync(key, items)
    end
end)

game.Players.PlayerRemoving:connect(function(player)
    local items = {shirt, pants, shirtg}
    local key = "user-" .. player.userId

    datastore:SetAsync(key, items)
end)
Ad

Answer this question