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

Are datastoreservice datastores broken?

Asked by 6 years ago

I have the following savedata script in serverscript service in one of my games:

local AUTO_SAVE = false         
local TIME_BETWEEN_SAVES = 60   
local PRINT_OUTPUT = false      
local SAFE_SAVE = false
---------------------------------

local players = game:GetService("Players")
local dataStoreService = game:GetService("DataStoreService")
local leaderboardData = dataStoreService:GetDataStore("LeaderStats")

local function Print(message)
    if PRINT_OUTPUT then print(message) end
end

local function SaveData(player)
    if player.userId < 0 then return end
    player:WaitForChild("leaderstats")
    wait()
    local leaderstats = {}
    for i, stat in pairs(player.leaderstats:GetChildren()) do
        table.insert(leaderstats, {stat.Name, stat.Value})
    end
    leaderboardData:SetAsync(player.userId, leaderstats)
    Print("Saved "..player.Name.."'s data")
end

local function LoadData(player)
    if player.userId < 0 then return end
    player:WaitForChild("leaderstats")
    wait()
    local leaderboardStats = leaderboardData:GetAsync(player.userId)
    for i, stat in pairs(leaderboardStats) do
        local currentStat = player.leaderstats:FindFirstChild(stat[1])
        if not currentStat then return end
        currentStat.Value = stat[2]
    end
    Print("Loaded "..player.Name.."'s data")
end

players.PlayerAdded:connect(LoadData)
players.PlayerRemoving:connect(SaveData)

if SAFE_SAVE then
    game.OnClose = function()
        for i, player in pairs(players:GetChildren()) do
            SaveData(player)
        end
        wait(1)
    end
end

while AUTO_SAVE do
    wait(TIME_BETWEEN_SAVES)
    for i, player in pairs(players:GetChildren()) do
        SaveData(player)
    end
end

In the game, it works perfectly. Never had a problem with it, always gets the data right, etc etc. In the process of building another game, I used the same script (save to roblox, open from mymodels) for this function and the same script that I had in the other game to create the stats.

to shorten: I have this script to save/load and another to create the stats for new players in a game. I have these identical scripts in another game I am building.

My problem is: In the new game (with nothing different) I get this error every time the script tries to load the playerdata on join, and then no other part of the script ever fires:

502: API Services rejected request with error: HTTP 0 (HTTP 403 (HTTP/1.1 403 Forbidden))

My script isn't even trying to connect using an api, it's just connecting to datastore service. Can anyone tell me what's going on here?!

The line that the error code comes up for is line 38 in the script. The script that has the error is the script attached.

0
reason I asked if they are broken is becuase this script still works in the other game DANISSY1 2 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

The error has nothing to do with the script, I don't really remember but it has either to do with not allowing studio access to the datastore or it is a team create problem (I don't remember as they look pretty much the same)

0
Alright. Do you remember how to fix either of those? DANISSY1 2 — 6y
1
Check "Your Game > ... > Configure this Game > Enable Studio Access to API Services" should be checked if you are testing from Studio. SametTurkey 1 — 6y
0
Team create cannot be fixed as only the owner can access datastores, if you want to test it with it you can copy the place, it will work in normal studios with both errors though User#20388 0 — 6y
0
(SametTurkey answered the studio access problem) User#20388 0 — 6y
View all comments (6 more)
0
What? The owner can access datastores and view what's in them? I've been looking to do that for ages! (If it's alright, please share how here) DANISSY1 2 — 6y
0
The owner can view the datastore data? I've been looking for how to do that for ages and it has not once come up with a result. As for the fixes, thanks. I'll try them out as soon as I can. DANISSY1 2 — 6y
0
You can view datastores but you'll have to know the players id (if you're working with a playerdatastore) and it needs to be ingame, you cannot view it from outside, please set this question to best answer User#20388 0 — 6y
0
answer* User#20388 0 — 6y
0
you got it right both times. I've set the question as answered. Thanks a lot for your help. DANISSY1 2 — 6y
0
Np :) User#20388 0 — 6y
Ad

Answer this question