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

This is my first time using datastores and I don't think I am doing it right?

Asked by 3 years ago

I have been practicing a lot of programming and right now I am doing datastores. I don't know what I am doing wrong but it won't save.

Here is my code:

local DSS = game:GetService("DataStoreService")
local ScoreSave = DSS:GetDataStore("ScoreSave")

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

    local Score = Instance.new("IntValue", leaderstats)
    Score.Name = "Score"
    Score.Value = 100

    local SavedScored
    local success, err = pcall(function()
        SavedScored = ScoreSave:GetAsync(plr.UserId.."-Score")
    end)
    if success then
        Score.Value = SavedScored
    else
        warn(err)
    end

end)

game.Players.PlayerRemoving:Connect(function(plr)
    local success, err = pcall(function()
        ScoreSave:SetAsync(plr.UserId.."-Score", plr.leaderstats.Score.Value)
    end)
    if success then
        print("Success")
    else
        warn(err)
    end
end)

I hope you can find what I am doing wrong.

0
Did you go to Alvin's tutorial? NathanBlox_Studios 212 — 3y
0
he probably is MmadProgrammer 35 — 3y
0
make sure api services are enabled MmadProgrammer 35 — 3y
0
I did it mostly from prior knowledge and used the roblox api for guidance. And yes, my api services are enabled blockydiamond01 0 — 3y

Answer this question