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

Why won't this code work / save?

Asked by
StoIid 364 Moderation Voter
8 years ago

This is supposed to be a DataStore script I did from a tutorial but it doesn't seem to work. Any idea what's wrong?

Here's part one of the script:

local DataStore = game:GetService("DataStoreService"):GetDataStore("LolWhyDa")


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

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

    local points = Instance.new("IntValue", stats)
    points.Name = "Points"

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

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

    local savedValues = DataStore:GetAsync(key)

    if savedValues then
        --Save Format: {points, coins}
        points.Value = savedValues.Value[1]
        coins.Value = savedValues.Value[2]
    else
        local valuesToSave = {points.Value, coins.Value}
        DataStore:SetAsync(key, valuesToSave)

    end
end)

Part 2, located in a seperate script

local DataStore = game:GetService("DataStoreService"):GetDataStore("LolWhyDa")


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

    local key = "user-"..player.userId
    --Save key: {points, coins}
    local valuesToSave = {player.leaderstats.Points.Value, player.leaderstats.Coins.Value}
    DataStore:SetAsync(key, valuesToSave)

end)

both scripts are in ServerScriptService.

0
leaderstats must be a model lucas4114 607 — 8y
0
I did that, still didn't save! StoIid 364 — 8y

2 answers

Log in to vote
1
Answered by 8 years ago

I know thisis not much help but this is where you can learn it http://wiki.roblox.com/index.php?title=Data_store

0
It doesn't. I tried many things it shows and they still won't work for me. StoIid 364 — 8y
Ad
Log in to vote
0
Answered by
IrishFix 124
5 years ago

With data stores it is dificult, but as johndeer said, that is the best place to start :/

Answer this question