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

How do I load my saved data?

Asked by
jdc892 4
6 years ago

this is the code I have so far

local DS1 = game:GetService("DataStoreService"):GetDataStore("Coins")
local DS2 = game:GetService("DataStoreService"):GetDataStore("Gems")
local DS3 = game:GetService("DataStoreService"):GetDataStore("equippedKnife")
local DS4 = game:GetService("DataStoreService"):GetDataStore("equippedGun")

game.Players.PlayerAdded:connect(function(player)

    local stats = Instance.new("IntValue", player)
    stats.Name = "leaderstats"

    local coins = Instance.new("IntValue", stats)
    coins.Name = "Coins"
    coins.Value = 50

    local gems = Instance.new("IntValue", stats)
    gems.Name = "Gems"
    gems.Value = 0

    local inGame = Instance.new("BoolValue", player)
    inGame.Name = "InGame"

    local equippedKnife = Instance.new ("StringValue", player)
    equippedKnife.Name = "equippedKnife"
    equippedKnife.Value = "Default"

    local equippedGun = Instance.new("StringValue", player)
    equippedGun.Name = "equippedGun"
    equippedGun.Value = "Default"

    while wait(60) do
        DS1:SetAsync(player.userId.."_DS1", coins.Value)
        print("Saved Coins")
        --Saved Coins
        DS2:SetAsync(player.userId.."_DS2", gems.Value)
        print ("Saved Gems")
        --Saved Gems
        DS3:SetAsync(player.userId.."_DS3", equippedKnife.Value)
        print ("Saved knifeEquipped")
        --Saved equipped Knife
        DS4:SetAsync(player.userId.."_DS4", equippedGun.Value)
        print ("Saved gunEquipped")
        --Saved equipped Gun
      end
end)

how would I load the stats everytime rather than just saving it?

0
Give me the code not a link to a guide, sorry but I am lazy and have already looked through most. jdc892 4 — 6y
0
This is a website that helps people with scripting, not fulfill their requests to code for them. KingLoneCat 2642 — 6y
0
sorry jdc892 4 — 6y

1 answer

Log in to vote
0
Answered by
Bertox 159
6 years ago
DS1:GetAsync(player.UserId)

Thats it! Very easy. Lol

0
thanks, how would I make it so that if they were new the "equippedKnife" and "equippedGun" values are "Default"? jdc892 4 — 6y
Ad

Answer this question