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

My DataStore/DataSave Script Wont Work And It Doesn't Give Any Errors???

Asked by 4 years ago

I've tried fixing the script moving the location and nothing works.

local ServerStorage = game:GetService("ServerStorage")
local DataStore = game:GetService("DataStoreService")
local TeamDataStore = DataStore:GetDataStore("PlayerTeamSave")
local Players = game:GetService("Players")

local SessionData = {}
local Auto_Save_Interval = 10

local function saveData(player)
    local playerUserId = player.UserId
    local attempt = tick()
    local success = nil
    repeat
        success = pcall(function()
            TeamDataStore:SetAsync(playerUserId, SessionData[playerUserId])
        end)
    until success or (tick() - attempt) >= 30
    if not success and (tick() - attempt) >= 30 then
        warn("Cannot save data for player!")
    end
    warn("LOL!!!")
end

local function autoSave(player)
    local playerUserId = player.UserId
    local Data = TeamDataStore:GetAsync(playerUserId)
    while wait(Auto_Save_Interval) do
        for playerUserId, Data in pairs(SessionData) do
            saveData()
        end
    end
end

local function setUpPlayerData(player)
    local playerUserId = player.UserId
    local success, yeiit = pcall(function()
        return TeamDataStore:GetAsync(playerUserId)
    end)
    if success then
        if yeiit then
            SessionData[playerUserId] = yeiit
        else
            SessionData[playerUserId] = {Team = "peasant"}
        end
    else
        warn("Cannot access data store for player!")
    end
end

Players.PlayerAdded:Connect(setUpPlayerData)
Players.PlayerRemoving:Connect(saveData)
warn("Running!!!")
0
there isn't anything in session data table so it's going to save an empty table duh AdminAyush 10 — 4y

Answer this question