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

Datastore not saving on player leaving, or value changing?

Asked by 4 years ago
Edited 3 years ago
local DS        = game:GetService("DataStoreService")-- Creating DataStores To Save Your Data
local GoldSave  = DS:GetDataStore("GoldSaveSystem")  --

game.Players.PlayerAdded:Connect(function(Player)                 -- When A Player Joins
    local Folder   = Instance.new("Folder",Player)                -- New Folder Inside Player Called  "leaderstats"
    Folder.Name    = "leaderstats"                                -- 

    local Gold     = Instance.new("IntValue",Folder)              -- Making A Value Inside The Player Named "Gold"
    Gold.Name      = "Gold"                                       --
    Gold.Value     = GoldSave:GetAsync(Player.UserId) or 0        --
    Gold.Changed:Connect(function()                               -- Saves Their Gold If They Earn Any          
        GoldSave:SetAsync(Player.UserId, Gold.Value)              --
    end)                                                          --

     -- If The XP Changes It Will Call The LevelUp Function
end)

game.Players.PlayerRemoving:Connect(function(Player)-- Saving Their Level Value
     -- Saving Their XP Value
    GoldSave:SetAsync(Player.UserId, Player.leaderstats.Gold.Value)  -- Saving Their Gold Value
end)                                                                 --

So, i have a datastore that is not saving. The loading is working as i went on the DataStore editor and it loads perfectly. But when i edit the data in leaderstats expecting it to save. It goes back to the values i inserted in datastore editor

1
Dude. Don't use 3 datastores for different properties. Just save a table value with the properties instead. Fifkee 2017 — 4y
0
Is APi service enabled make sure it is and try publishing it. JesseSong 3916 — 4y
0
@JesseSong yes my api service is enabled. User#22145 0 — 4y
1
mate, you literally only need 1 Datastore, you dont need 3 Uzixt 19 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

I've had the exact same problem with datastores, however, the only one which worked for me was

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("WaveSaveSystem")

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

    local Wave = Instance.new("IntValue",player)
    Wave.Name = "Diamond"
    Wave.Value = ds:GetAsync(player.UserId) or 1
    Wave.Changed:connect(function()
        ds:SetAsync(player.UserId, Wave.Value)

    end)
end)

game.Players.PlayerRemoving:connect(function(player)
    ds:SetAsync(player.UserId, player.Wave.Value)
end)
Ad

Answer this question