[SOLVED] Why Is My DataStore Giving A 404 Error?

  1. What do you want to achieve? Keep it simple and clear!
    a table datastore

  2. What is the issue? Include screenshots / videos if possible!
    it gave me a 404 error when i called the datastore, now without modifying the code at all, its giving me a “Access forbidden”

the issue appears to be in the saving area, not the loading area, however i included both parts of the script.
current error:

Old 404 error:

  1. What solutions have you tried so far? Did you look for solutions
    I’ve looked for solutions on YT, and devforum, however i haven’t seen any solutions that work

script:

local dataStoreService = game:GetService("DataStoreService")
local DataStore = dataStoreService:GetDataStore("MyDataStore")

game.Players.PlayerAdded:Connect(function(player)

	local leaderstats2 = Instance.new("Folder")
	leaderstats2.Name = "leaderstats2"
	leaderstats2.Parent = player

	local loads = Instance.new("NumberValue")
	loads.Name = "Loads"
	loads.Value = 0
	loads.Parent = leaderstats2


    local playerkey = player.UserId..player.Name

	wait(3)

	-- Loading Data
	local LoadsData
	local success, errormessage = pcall(function()
		LoadsData = DataStore:GetAsync(playerkey)
	end)

	if success then
		loads.Value = LoadsData
	end
end)

game:BindToClose(function()
	for _, player in pairs(game.Players:GetPlayers()) do
		local playerId = player.UserId..player.Name
		local tableSaved = {}

		-- Saving loads
		
		local loadsValue = player.leaderstats2.Loads.Value
		table.insert(tableSaved, 1, loadsValue)
		table.insert(tableSaved, 2, loadsValue + 300) -- for testing)

		local success, errormessage = pcall(function()
			DataStore:SetAsync(playerId, tableSaved)	
		end)
	end
end)
1 Like

I don’t know if it’s right, because I’m not a professional in scripting, but you want to SetAsync PlayerId with table, but then when you want to GetAsync it, you using player.userid and player.name datastore. It’s looks like two different datastores

1 Like

Thanks for a quick reply however unfortunately that’s not the problem. i just used 2 different variable names:

UPDATE: I’m now getting a different error! without modifying my code at all!

Good golly am i goofy today, i forgot to allow them!:

2024-01-14_15-24-45

Try this:

  1. Create a script, where you type:
    game.Players.PlayerAdded:Connect(function(Player)
    local leaderstats2 = Instance.new(“Folder”)
    leaderstats2.Name = “leaderstats2”
    leaderstats2.Parent = Player

    local loads = Instance.new(“NumberValue”)
    loads.Name = “loads”
    loads.Parent = leaderstats2
    end

  2. After it, add a new script with text:

game.Players.PlayerRemoving:connect(function(player)
local datastore = game:GetService(“DataStoreService”):GetDataStore(player.Name…“YourDataStoreName”)

local statstorage = player:FindFirstChild(“leaderstats2”):GetChildren()
for i = 1, #statstorage do
datastore:SetAsync(statstorage[i].Name, statstorage[i].Value)
end
end)

local player = game.Players.PlayerAdded:connect(function(player)
local datastore = game:GetService(“”):GetDataStore(player.Name…“YourDataStoreName”)
player:WaitForChild(“leaderstats2”)
wait()
local stats = player:FindFirstChild(“leaderstats2"):GetChildren()
for i = 1, #stats do
stats[i].Value = datastore:GetAsync(stats[i].Name)
end
end)

apologies for wasting your time! thanks for the help though!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.