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

Saving System (gems and rebirths are not saving)?

Asked by 2 years ago

Hey Guys my Gems and rebirths are not saving but my clicks do can anyone help me ?

``local  dataStoreService = game:GetService("DataStoreService")
local clicksDataStore = dataStoreService:GetDataStore("Clicks1")
local rebirthsDataStore = dataStoreService:GetDataStore("Rebirths")
local gemsDataStore = dataStoreService:GetDataStore("Gems")

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

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

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

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

    local playerUserId = "player_" ..player.UserId

    -- Loading Data
    local clicksData
    local success, errormessage = pcall(function()
        clicksData = clicksDataStore:GetAsync(playerUserId)
    end)

    if success then
        clicks.Value = clicksData
    end


    -- Loading Rebiths Data
    local rebirthsData
    local success, errormessage = pcall(function()
        rebirthsData = rebirthsDataStore:GetAsync(playerUserId)
    end)

    if success then
        rebirths.Value = rebirthsData
    end

    -- Loading Gems Data
    local gemsData
    local success, errormessage = pcall(function()
        gemsData = gemsDataStore:GetAsync(playerUserId)
    end)

    if success then
        gems.Value =    gemsData
    end 
end)

-- Saving Data
game.Players.PlayerRemoving:Connect(function(player)
    local playerUserId = "player_" ..player.UserId

    -- Saving Clicks
    local clicksValue = player.leaderstats.Clicks.Value

    local success, errormessage = pcall(function()
        clicksDataStore:SetAsync(playerUserId, clicksValue)
    end)

    --Saving Rebirths
    local   rebirthsValue = player.leaderstats.Rebirths.Value

    local success, errormessage = pcall(function()
        rebirthsDataStore:SetAsync(playerUserId, rebirthsValue)
    end)

    --Saving Gems Data
    local   gemsValue = player.leaderstats.Gems.Value

    local success, errormessage = pcall(function()
        gemsDataStore:SetAsync(playerUserId, gemsValue)
    end)
end)

game:BindToClose(function(player)
    for _, Player in pairs(game.Players:GetPlayers()) do

        local playerUserId = "player_"..Player.UserId

        -- Saving Clicks
        local clicksValue = player.leaderstats.Clicks.Value

        local success, errormessage = pcall(function()
            clicksDataStore:SetAsync(playerUserId, clicksValue)
        end)
        --Saving Rebirths
        local   rebirthsValue = player.leaderstats.Rebirths.Value

        local success, errormessage = pcall(function()
            rebirthsDataStore:SetAsync(playerUserId, rebirthsValue)
        end)

        --Saving Gems Data
        local   gemsValue = player.leaderstats.Gems.Value

        local success, errormessage = pcall(function()
            gemsDataStore:SetAsync(playerUserId, gemsValue)
        end)
    end
end)``
0
ignore these : `` RoseHickman8 0 — 2y
0
Are you testing this script in studio, or in game? I've had issues where saving data in a testing session doesn't save to the service. loowa_yawn 383 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

Try turning on API services and publishing the game

Ad

Answer this question