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

DataStore Failure, Will not save data onPlayerRemoving?(DataStore2)

Asked by
BryanFehr 133
4 years ago

Hello all!

I've been experimenting with DataStore2, and been able to accomplish tool persistence with it, but I am struggling to get my currency to save!

I have no idea where the problem lies, the Module for DataStore2 is inside the ServerScriptService, I do not know if this may be the problem, or what, but my script is below!

Any and ALL help is appreciated! :)

local DataStore2 = require(game.ServerScriptService:WaitForChild("MainModule"))

local defaultValue = 0

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

    local shardsDataStore = DataStore2("Shards",plr)
    local minsplayedDataStore = DataStore2("minsplayed",plr)

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

    local shards = Instance.new("IntValue",leaderstats)
    shards.Name = "Shards"

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

    local function shardsUpdate(updatedValue)
        shards.Value = shardsDataStore:Get(updatedValue)
    end

    local function minsplayedUpdate(updatedValue)
        minsplayed.Value = minsplayedDataStore:Get(updatedValue)
    end

    shardsUpdate(defaultValue)
    shardsDataStore:OnUpdate(shardsUpdate)

    minsplayedUpdate(defaultValue)
    minsplayedDataStore:OnUpdate(minsplayedUpdate)

end)

Answer this question