Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 6 days 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 100 — 6d
0
he probably is MmadProgrammer 35 — 6d
0
make sure api services are enabled MmadProgrammer 35 — 6d
0
I did it mostly from prior knowledge and used the roblox api for guidance. And yes, my api services are enabled blockydiamond01 0 — 6d

Answer this question