Datastores not loading

Hey! My datastore is failing to load player’s data and won’t print any errors so I’m not sure what is causing this issue and any help with it would be appreciated. Thanks! :heart:

:scroll: Code:

local DSS = game:GetService("DataStoreService")
local PlayerData = DSS:GetDataStore("Test4")
-- Locals

local StatsTable = {
	
}
-- Stats
local name = "Stats"
local Data_Load_Interval = 0.1
local MaxLuck = 100
local CurrentLuck = 0 -- Loading Server Lucks
local DoneLoadingLuck = false 
local LuckCounter = 0 -- Replicating player lucks
local SavingLuck = 0 -- saving the current luck of player 
-- Settings 

local function ReplicateLuckToPlayer(player)
	if player ~= nil then
		repeat
		LuckCounter += 1
		local Cloned = game.ReplicatedStorage:WaitForChild("Luck"):Clone()
		Cloned.Name = "Luck"..LuckCounter
		Cloned.Parent = player.PlayerGui:WaitForChild("MainGui"):WaitForChild("Luck Info"):WaitForChild("ScrollingFrame")
	until LuckCounter >= MaxLuck
	if LuckCounter >= MaxLuck then
		return true
	else
		return false
	end
	end
end

repeat
	CurrentLuck += 1
	local NA = "Luck"..CurrentLuck
	if NA ~= CurrentLuck then
	StatsTable[NA] = 0
	end
until CurrentLuck >= MaxLuck
DoneLoadingLuck = true

game.Players.PlayerAdded:Connect(function(p)
	local Finished = false
	local prefix = p.UserId
	local l = Instance.new("Folder")
	l.Name = name
	l.Parent = p
	task.wait(Data_Load_Interval)
	if not DoneLoadingLuck then
		print("Table not loaded")
		p:Kick("System failed to load.. your stats are fine dw")
	else
		local data
		local s, v = pcall(function()
			data = PlayerData:GetAsync(prefix)
		end)
		if s and data then
			print("Making Lucks")
			for ReplicateName,O in pairs(StatsTable) do
				local NewValue = Instance.new("NumberValue")
				NewValue.Name = ReplicateName
				NewValue.Value = O
				NewValue.Parent = l
			end
			repeat
				wait(1)
				local PlayersInv = #p:WaitForChild(name):GetChildren()
				print("Waiting")
			until PlayersInv >= MaxLuck
			print("Finding Lucks In DataStore")
				for nothingdontmind, valueofcurent in pairs(game.Players:WaitForChild(name):GetChildren()) do
				print(valueofcurent.Name)
				if table.find(data, valueofcurent.Name) then
					
					local index = table.find(data, valueofcurent.Name)
					
					valueofcurent.Value = data[index]
				end					
			end
			local LuckRepl = ReplicateLuckToPlayer(p)
			if LuckRepl == false then
				p:Kick("Failed to replicate")
			else
				LuckCounter = 0
			end
		else
			print("New Player so Ok?")
			for ReplicateName,O in pairs(StatsTable) do
				local NewValue = Instance.new("NumberValue")
				NewValue.Name = ReplicateName
				NewValue.Value = O
				NewValue.Parent = l
				print(NewValue.Name)
			end
			repeat
				wait(.1)
				local WAAIT = #p:WaitForChild(name):GetChildren()
			until WAAIT >= MaxLuck			
			local LuckRepl = ReplicateLuckToPlayer(p)
			if LuckRepl == false then
				p:Kick("Failed to boom")
			else
				LuckCounter = 0
			end
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
    local PrimaryTable = {}
    
    for i, v in pairs(plr.Stats:GetChildren()) do
        PrimaryTable[v.Name] = v.Value
    end
    
    local s, e = pcall(function()
        PlayerData:SetAsync(plr.UserId, PrimaryTable)
    end)
    if s then
        print(table.unpack(PrimaryTable))
    end
end)

Probably you don’t get an error cuz the error is inside a pcall, so that a clue

1 Like

Wait, I can’t find any SetAsync where are you storing the data?

Forgot to include this, I’ll edit the OP now.

game.Players.PlayerRemoving:Connect(function(plr)
    local PrimaryTable = {}
    
    for i, v in pairs(plr.Stats:GetChildren()) do
        PrimaryTable[v.Name] = v.Value
    end
    
    local s, e = pcall(function()
        PlayerData:SetAsync(plr.UserId, PrimaryTable)
    end)
    if s then
        print(table.unpack(PrimaryTable))
    end
end)
game.Players.PlayerAdded:Connect(function(plr)
	local Finished = false
	local prefix = plr.UserId

Can you try this, change playerAdded to plr and the variable prefix to

Put the following code above this:

if not s then
    warn("Could not get data: " .. v)
end

None of the replied solutions worked, however I later ended up figuring out the issue and solved this myself. Thanks to everyone who tried to help.

The issue was that game.Players should’ve been plr:WaitForChild().