Failed to save data: Request Denied

Hi there, I have tried to make an API for a ticket checker when pressing a button I made. When being in game in roblox it says “Failed to save data: Request Denied” for some reason when it clearly works in roblox studio. I havn’t changed anything from the script just tested in game and in studio

We need to see some of the code in order to help

Ah sorry, JavaScript or the Lua script? @PoppyandNeivaarecute

Give us the Lua script. I’d imagine you are creating this in Roblox Studio?

local serverUrl = “myapilinkhereihavehiddenit:)”

Why don’t you use the Roblox datastore? Is there a reason you are using that particular database? Here is the datastore version of your code if you want to see it.

local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")

-- Get a reference to a specific DataStore
local playerDataStore = DataStoreService:GetDataStore("PlayerData")

local function onPlayerAdded(player)
    local userId = tostring(player.UserId)
    local displayName = player.Name

    local ticketClasses = {"Economy", "Premium"}
    local ticketClass = ticketClasses[math.random(1, #ticketClasses)]

    print("Player joined with user ID:", userId)
    print("Generated ticket class for new player:", ticketClass)
    print("Player's display name:", displayName)

    local data = {
        ticketType = ticketClass,
        displayName = displayName
    }

    local success, errorMessage = pcall(function()
        -- Save or update the player's data in the DataStore
        playerDataStore:SetAsync(userId, data)
    end)

    if success then
        print("Data saved or updated successfully for user:", userId)
    else
        warn("Failed to save or update data for user:", userId, errorMessage)
    end
end

-- Connect the onPlayerAdded function to the PlayerAdded event
Players.PlayerAdded:Connect(onPlayerAdded)

If you are trying to still use your method, please add the JSON script.

1 Like

I am storing information of the user once they use a UI I made to a express web server (this is a work around to link to games between each other) and then using GET from a the API to get the information so I can do what I need.

Javascript you mean right just to be sure since the JSON file is the what my code 1 does to convert the userid information to a JSON then the API can read it and convert it back to a way roblox can un understand it.