Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

DataStore refusing to load data?

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)

6 comments

1

Actually, you can type userId as of now and it still works.

1

But, it is deprecated so it would be best to start using UserId

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"

0

I have already

0

legends say the datastore refuses to load data to this day.

0

Make sure that it is your game, make sure you have internet, etc

1 answer

✓ Accepted answer

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)

2 comments

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

0

Aww thanks alteast I’m not left out

This discussion is preserved as it was. New answers, comments, and votes are closed.