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

Why is my datastore not getting the data?

Asked by 4 years ago

I'm sorry, I'm new to DataStores.

local DataStoreService = game:GetService("DataStoreService")

local myDataStore = DataStoreService:GetDataStore("DATA")

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"

    local tokens = Instance.new("IntValue", leaderstats)
    tokens.Name = "Tokens"
    tokens.Value = 0

    local data

    local success, errormessage pcall(function()
        data = myDataStore:GetAsync(player.UserId.."-Tokens")
    end)

    if success ~= nil then
        tokens.Value = data
    else
        print("There was an error while getting your data.")
        warn(errormessage)
    end
end)

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

    local success, errormessage = pcall(function()
        myDataStore:SetAsync(player.UserId.."-Tokens",player.leaderstats.Tokens.Value)
    end)

    if success then
        print("Data succesfully saved.")
    else
        print("There was an error when saving data.")
        warn(errormessage)
    end

end)
0
I've already enabled API services. AcrylixDev 119 — 4y

1 answer

Log in to vote
1
Answered by
ImTrev 344 Moderation Voter
4 years ago

I only looked at it for a second but I saw on line 15 you forgot an "=".

Ad

Answer this question