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

My datastore script doesnt work? Ive enabled api services aswell, but still nothing!

Asked by
R3M_1 11
2 years ago

I've made 2 scripts, The first is the script for my datastore itself, the next is for the leaderstats. The script doesnt toss any errors, and i also have api enabled! But it doesnt save my stats.

DataStore Script

local ds = game:GetService("DataStoreService"):GetDataStore("dataStore")

game.Players.PlayerAdded:Connect(function(plr)
    wait()
    local key = "user_"..plr.UserId

    local save1 = plr.leaderstats.Clicks
    local save2 = plr.leaderstats.Rebirths
    local save3 = plr.leaderstats.Gems

    local getSaved = ds:GetAsync(key)

    if getSaved then
        save1.Value = getSaved[1]
        save2.Value = getSaved[2]
        save3.Value = getSaved[3]
    else
        local NumbersForSaving = {save1.Value, save2.Value, save3.Value}

        ds:GetAsync(key, NumbersForSaving)
    end
end)

game.Players.PlayerRemoving:Connect(function(player)
    local save1 = player.leaderstats.Clicks
    local save2 = player.leaderstats.Rebirths
    local save3 = player.leaderstats.Gems

    ds:SetAsync("user_"..player.UserId, {save1.Value, save2.Value, save3.Value})
end)

leaderstats Script

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

    local leaderstats = Instance.new("Folder", plr)
    leaderstats.Name = "leaderstats"


    local clicks = Instance.new("IntValue", leaderstats)
    clicks.Name = "Clicks"



    local rebirths = Instance.new("IntValue", leaderstats)
    rebirths.Name = "Rebirths"


    local gems = Instance.new("IntValue", leaderstats)
    gems.Name = "Gems"


end)
0
I would advise you to probably create the leaderstats folder and values all in 1 script. This allows you to organize it better. SpiritualSonicdash 67 — 2y

Answer this question