DataStore not retrieving data

why would it be any different in a modulescript?

Script, LocalScript, ModuleScript, is your script getting disabled by something?

No I’ve tested with prints it doesn’t get disabled it just says there is no data with getAsync

I can’t find anywhere in the code where you set data for new players, try add a


Startsuccess = pcall(function()
				playerData:SetAsync(playerUserId, sessionData[playerUserId]) -- change sessionData[playerUserId] to the new players data if it's not this.
	end)
if Startsuccess then 
print("Successfully set data for new player")
end

if the player has no data

1 Like

It does it here

local function savePlayerData(playerUserId)
	if sessionData[playerUserId] then
		local tries = 0
		local success
		repeat
			tries = tries + 1
			success = pcall(function()
				playerData:SetAsync(playerUserId, sessionData[playerUserId])
				print("Data Save Request")
			end)
			if not success then wait(1) end
		until tries == 3 or success
		if not success then
			warn("Cannot save data for player!")
		end
		if success then
			print("Data Saved")
		end
	end
end

local function saveOnExit(player)
	local playerUserId = "Player_"..player.UserId
	savePlayerData(playerUserId)
end

This is on exit, what about on join? You need to set some data for the new players joining.

it prints out no data found while I clearly did save the data

local function setupPlayerData(player)
	local playerUserId = "Player_"..player.UserId
	local success, data = pcall(function()
		local data = playerData:GetAsync(playerUserId)
	end)
	if success then
		if data then
			sessionData[playerUserId] = data
			print("Data Found")
		else
			sessionData[playerUserId] = {Coins=0, Stages=0, Level=0, Rebirths=0, Areas=1, Exp=0, MaxExp=10}
			print("No Data Found")
		end
	else
		warn("Cannot save data for player!")
	end
end

game.Players.PlayerAdded:Connect(setupPlayerData)
local function setupPlayerData(player)
	local playerUserId = "Player_"..player.UserId
	local success, data = pcall(function()
		local data = playerData:GetAsync(playerUserId)
	end)
	if success then
		if data then
			sessionData[playerUserId] = data
			print("Data Found")
		else
			sessionData[playerUserId] = {Coins=0, Stages=0, Level=0, Rebirths=0, Areas=1, Exp=0, MaxExp=10}
print("No Data Found")
startsuccess = pcall(function()
				playerData:SetAsync(playerUserId, sessionData[playerUserId])
	end)
if startsuccess then
print("New Data Saved")
end
			
		end
	else
		warn("Cannot save data for player!")
	end
end

game.Players.PlayerAdded:Connect(setupPlayerData)

Change it to this.

I did this and now it prints out the warn from if not startsuccess

local function setupPlayerData(player)
	local playerUserId = "Player_"..player.UserId
	local success, data = pcall(function()
		local data = playerData:GetAsync(playerUserId)
	end)
	if success then
		if data then
			sessionData[playerUserId] = data
			print("Data Found")
		else
			local startsuccess = pcall(function()
				playerData:SetAsync(playerUserId, sessionData[playerUserId])
			end)
			if startsuccess then
				print("New Data Saved")
			end
			if not startsuccess then
				warn("Cannot save data for player")
			end
		end
	else
		warn("Cannot save data for player!")
	end
end
local function setupPlayerData(player)
	local playerUserId = "Player_"..player.UserId
	local success, data = pcall(function()
		local data = playerData:GetAsync(playerUserId)
	end)
	if success then
		if data then
			sessionData[playerUserId] = data
			print("Data Found")
		else
sessionData[playerUserId] = {Coins=0, Stages=0, Level=0, Rebirths=0, Areas=1, Exp=0, MaxExp=10}
			local startsuccess = pcall(function()
				playerData:SetAsync(playerUserId, sessionData[playerUserId])
			end)
			if startsuccess then
				print("New Data Saved")
			end
			if not startsuccess then
				warn("Cannot save data for player")
			end
		end
	else
		warn("Cannot save data for player!")
	end
end

You need the sessiondata thing

Just as I expected it doesn’t work. The problem is with for some reason the GetAsync not working.

I’m unsure, honestly sorry, can’t help you have no clue.

You are trying to save a list. DataStores Are Made To Save String Or Intigers. A Table Value Wont Save.