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

Getting 403 error when trying to save leaderstats data how do I fix?

Asked by 5 years ago

I just want to save the value of wins and im getting this error:

17:27:44.287 - 502: API Services rejected request with error. HTTP 403 (Forbidden)

This is my code located in a script called Stats in ServerScriptService

I got most of this from the guide on scriptinghelpers about saving and loading data

local DSS = game:GetService("DataStoreService")

local datastore = DSS:GetDataStore("GeneralSaveData", "Players")


game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local wins = Instance.new("IntValue")
    wins.Name = "Wins"
    wins.Value = 0
    wins.Parent = leaderstats
end)

function generateDataKey(player)
    local ret = "uid_" .. player.userId
    return ret
end

function generateDataTable(player)
    local dataTable = {
         -- CHANGE THESE TO ADAPT TO YOUR LEADERSTATS
        Wins = player.leaderstats.Wins.Value
    }
    return dataTable
end

function saveDataForPlayer(player)
    local key = generateDataKey(player)
    local data = generateDataTable(player)
    datastore:SetAsync(key, data)
end

function inputDataToPlayer(player, data)

    player.leaderstats.Wins.Value = data.Wins
end

function loadDataForPlayer(player)
    local key = generateDataKey(player)
    local data = datastore:GetAsync(key)
    inputDataToPlayer(player, data)
end

game.Players.PlayerAdded:connect(function(player)
    loadDataForPlayer(player) --Load first thing when they join
    player.leaderstats.Wins.Changed:connect(function()
        saveDataForPlayer(player) --Save the data when Wins changes value
    end)
end)

game.Players.PlayerRemoving:connect(saveDataForPlayer) --Save data when the player leaves the game

1 answer

Log in to vote
0
Answered by 5 years ago

On the Roblox "Create" page, find your game, select the cog next to edit, select Configure Game, and tick "Enable Studio Access to API Services". Save, and restart Studio.

How this works Basically, Roblox prevents Studio from using API Services, e.g. Data Stores, by default. Ticking this box will allow Studio to use them.

Ad

Answer this question