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.
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)