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

DataStore refusing to load data?

Asked by 6 years ago

I have tried numerous ways to get it to work, unsure if it is a bug or not but can someone help me please The error I keep receiving is 19:29:22.015 - 502: API Services rejected request with error: HTTP 0 (HTTP 403 (HTTP/1.1 403 Forbidden)) Here is the script if you want to have a look at it.

local data = game:GetService("DataStoreService")
local datastore = data:GetDataStore("RebornDataInitialiser")

game.Players.PlayerAdded:Connect(function(player)
    local userid = tostring(player.userId)
    local data1 = Instance.new("Folder")
    data1.Name = "Data"
    data1.Parent = player
    local xp = Instance.new("IntValue")
    xp.Name = "XP"
    xp.Value = 0
    xp.Parent = data1
    local level = Instance.new("IntValue")
    level.Name = "Level"
    level.Value = 0
    level.Parent = data1
    local saving = datastore:GetAsync(userid)

    if saving then
        level.Value = saving[1]
        xp.Value = saving[2]
    else
        local plr_data = {level.Value, xp.Value}
        datastore:SetAsync(userid, plr_data)

        game.Players.PlayerRemoving:Connect(function(player)
            local id = tostring(player.userId)
            local plr_data2 = {player.Data.Level.Value, player.Data.XP.Value}
            datastore:SetAsync(id, plr_data2)
        end)
    end
end)
1
Actually, you can type userId as of now and it still works. PoePoeCannon 519 — 6y
1
But, it is deprecated so it would be best to start using UserId PoePoeCannon 519 — 6y
1
Make sure the API Services are enabled first. You can check this if you go to the game settings and enable "Enable Studio Access to API Services" BloxRoxe 109 — 6y
0
I have already MaximumOverdriven 152 — 6y
View all comments (2 more)
0
legends say the datastore refuses to load data to this day. ShadyShock 77 — 6y
0
Make sure that it is your game, make sure you have internet, etc greatneil80 2647 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago

I’m not so sure but when I’ve tested this out before I’d get that error message and I would just put some waits in, which would mostly resolve my issue

local data = game:GetService("DataStoreService")
local datastore = data:GetDataStore("RebornDataInitialiser")

game.Players.PlayerAdded:Connect(function(player)
    local userid = tostring(player.userId)
wait(2)
    local data1 = Instance.new("Folder")
    data1.Name = "Data"
    data1.Parent = player
wait(2)
    local xp = Instance.new("IntValue")
    xp.Name = "XP"
    xp.Value = 0
    xp.Parent = data1
wait(2)
    local level = Instance.new("IntValue")
    level.Name = "Level"
    level.Value = 0
wait(2)
    level.Parent = data1
    local saving = datastore:GetAsync(userid)

    if saving then
        level.Value = saving[1]
        xp.Value = saving[2]
    else
        local plr_data = {level.Value, xp.Value}
        datastore:SetAsync(userid, plr_data)

        game.Players.PlayerRemoving:Connect(function(player)
            local id = tostring(player.userId)
            local plr_data2 = {player.Data.Level.Value, player.Data.XP.Value}
            datastore:SetAsync(id, plr_data2)
        end)
    end
end)
0
I managed to make it work before your answer, but considering your the only person to take the initiative and help, I'll accept your answer :) MaximumOverdriven 152 — 6y
0
Aww thanks alteast I’m not left out GizmoProductions 61 — 6y
Ad

Answer this question