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

DATA STORE WONT SAVE? [PLEASE HELP]

Asked by
Oficcer_F 207 Moderation Voter
5 years ago
Edited 5 years ago

I dont get any errors. And I dont see what I did wrong.

local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")


local DataStore = DataStoreService:GetDataStore("NameHere")


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

    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local points = Instance.new("IntValue")
    points.Name = "Points"
    points.Parent = leaderstats

    local coins = Instance.new("IntValue")
    coins.Name = "Coins"
    coins.Parent = leaderstats



    local Key = "player-"..player.UserId -- key

    local success, message = pcall(function() 
    SavedStats = DataStore:GetAsync(Key)
    end)




    if SavedStats then
        points.Value = SavedStats[1]
        coins.Value = SavedStats[2]
    else
        local Values = {
            points.Value;
            coins.Value
        }

        local success, message = pcall(function()
            DataStore:SetAsync(Key, Values)
        end)
    end

 Key = "player-"..player.UserId

        valuesToSave = {
        player.leaderstats.Points.Value;
        player.leaderstats.Coins.Value}

    local succes, message pcall(function() -- Stops errors
        DataStore:SetAsync(Key, valuesToSave)
    end)

game.Players.PlayerRemoving:Connect(function(player)
    local success, message = pcall(function()
    DataStore:SetAsync(Key, valuesToSave)
    end)

end)

end)

0
Watch PeasFactory's video, and copy exactly the code. Don't use pcalls for now. Also, what do you define as "working"? Pojoto 329 — 5y
0
So maybe I just had a typo on peas factorys? Are you sure his worked? I will try out tomorrow! Oficcer_F 207 — 5y

Answer this question