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

What am I doing wrong when creating this data store?

Asked by 4 years ago
local DSS = game:GetService("DataStoreService")
local CoinStore = DSS:GetDataStore("CoinStore")

game.Players.PlayerAdded:Connect(function(Player)
    local PlayerFolder = Instance.new("Folder", Player)
    PlayerFolder.Name = "PlayerFolder"
    local Coins = Instance.new("IntValue", PlayerFolder)
    Coins.Name = "Coins"

    local CoinData


    local Success, ErrorMesesage = pcall(function()
    CoinData = CoinStore:GetAsync(Player.UserId.."-coins")
    end)
    if Success then
        Coins.Value = CoinData
    else
        warn("Did not load data.")
    end

end)

game.Players.PlayerRemoving:Connect(function(Player)

    local Success, Error = pcall(function()
        CoinStore:SetAsync(Player.UserId.."-coins", Player.PlayerFolder.Coins.Value)
    end)

    if Success then
        print("It was a success")
    else
        warn(Error)
        print("Not successful")
    end

end)

I'm just beginning to learn how to use data stores and looked at a few different ways people have done them and I can't see any problems with what I have. I really want to get better at understanding and using data stores. Does anyone see anything wrong that would prevent this from working at all?

When I test it, Nothing shows up in the output at all. Leading me to think that I have not set it up properly.

0
Did you use a LocalScript or a server-sided Script? Bust2Death 0 — 4y
0
I used a server-sided script. The parent of the script is ServerScriptService. bubblegum41 3 — 4y

Answer this question