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

Why wont my datastore save data?

Asked by 4 years ago

I am trying to make a obby, but it wouldn't save, and I know that because after a lot of looking at the datastore editor and debugging using print. Here's my code:

local service = game:GetService("DataStoreService")
local datastore = service:GetDataStore("StageData") -- Do NOT touch "StageData" or ALL data will be erased.

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

    local data

    local y,n = pcall(function()
        data = datastore:GetAsync(player.UserId.."-stage")
    end)

    if y then
        if data then
            player.Team = game.Teams[data]
        end
    else
        print("Something went wrong, reseting progress..")
        warn(n)
        player.Team = game.Teams["Stage 1"]
    end

    player:LoadCharacter()

end)

game.Players.PlayerRemoving:Connect(function(player)

    local y,n = pcall(function()
        datastore:SetAsync(player.UserId.."-stage",player.Team.Name)
    end)

    if y then
        print("All went well, saved with value of "..player.Team.Name)
    elseif n then
        print("Something went wrong")
        warn(n)
    end

end)
0
some times it doesn't save. That may be your issue Dexiber 272 — 4y
0
I've tried many times. OrchidDumpling 16 — 4y

Answer this question