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

DataStore not saving, printing error message?

Asked by 3 years ago
Edited 3 years ago

On line 17 I get print error I dont know why this is happening? I get error 502: API Services rejected request with error. HTTP 403 (Forbidden)

local DS = game:GetService("DataStoreService")
local DS1 = DS:GetDataStore("SaveJoins")

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = player:WaitForChild("leaderstats")
    local joins = Instance.new("IntValue")
    joins.Name = "Joins"
    joins.Parent = leaderstats
    local PlayerUserId = "Player_"..player.UserId

    local data
    local success, errormessage = pcall(function()
        data = DS1:GetAsync(PlayerUserId)
    end)
    if success then
        joins.Value = data + 1
    else
        print("error")
        warn(errormessage)
    end
end)

game.Players.PlayerRemoving:Connect(function(player)
    local PlayerUserId = "Player_"..player.UserId
    local data = player.leaderstats.Joins.Value
    local success, errormessage = pcall(function()
        DS1:SetAsync(PlayerUserId, data)
    end)
    if success then
        print("success")
    else
        print("error")
        warn(errormessage)
    end
end)

2 answers

Log in to vote
2
Answered by
Zeuxulaz 148
3 years ago
Edited 3 years ago

Go to Game Settings in studio and press Options. Then, turn "Enable API Services" on.

Ad
Log in to vote
0
Answered by 3 years ago

Saw on line 11 I put local data.. I removed it and it worked?

0
Oh... that's strage. Zeuxulaz 148 — 3y

Answer this question