Player data not saving?

Recently, I’ve been trying to work on my build in my building game, but it hasn’t been saving anything. Not even destroying blocks.

I first thought it was because the datastore hit the limit, but even destroying blocks didn’t save.

I then tried putting it in a bind to close, but still, no saving.

If you know the issue, please let me know!

function saveData(player: Player)
	local islandFolder = workspace:FindFirstChild(player.UserId .. "_Island")
	local totalBlocks = #islandFolder.Blocks:GetChildren()
	local batchSize = 200
	local index = 0
	if islandFolder then
		local blocks = {}
		for _, block in pairs(islandFolder.Blocks:GetChildren()) do
			index += 1
			local blockData = {
				Position = Utils.vec3ToTable(block.PrimaryPart.Position),
				Rotation = Utils.CFrameAnglesToTable(block.PrimaryPart.Orientation),
				Type = block.Name
			}
			table.insert(blocks, blockData)

			block:Destroy()

			if index % batchSize == 0 or index == totalBlocks then
				task.wait(0.1)
			end
		end
		local ok, err = pcall(PlayerState.Set(player, "Island", blocks))

		if not ok then
			warn(err)
		end

		islandFolder:Destroy()
	end

	playerLocationStore:RemoveAsync(tostring(player.UserId))
	publicIslandsMap:RemoveAsync(tostring(player.UserId))
end
2 Likes

You need to wrap your pcall into a function, not call your PlayerState directly. Try doing:

local ok, err = pcall(function()
	PlayerState.Set(player, "Island", blocks)
end)

I would also save on PlayerRemoving AND BindToClose.

i said i tried putting it in a bind to close and it still didnt work

Do you save on PlayerRemoving now or only on BindToClose? And did you try the pcall then?

I save on both, and I tried the pcall, still no.


image
I break these grass blocks to test, but when I rejoin, they are back

1 Like

Do you save in the pcall or where exactly?

PlayerState.Set(player, "Island", blocks)

And you dont get any warning that the data save failed in err?

1 Like
local ok, err = pcall(function()
PlayerState.Set(player, "Island", blocks)
)

if not ok then
warn(err)
end

doesn’t warn anything

and btw I test in studio and the real game, and it doesn’t work for either

If none of the previous solutions work, then the problem might rely somewhere else from this code.

Assuming that you’ve used pcall with the right arguments, your statements are actually being executed (e.g. check using breakpoints, is the IF statement executed?,etc…), there’s no logical errors (e.g. islandFolder.Blocks actually has blocks inside of it), and you’re not negatively interfering with the internal datastore setup by PlayerState, then I can only guess it’s something else we can’t see here.

But I assume this was previously working? (seems like you have data already saved)

Yeah I guess the saving happens in the PlayerState Module. Could you give us the code there?

Also. What do you want to archieve with RemoveAsync? Wont this delete the data in the datastore?

The RemoveAsync stuff is for public island things, it’s a MemoryStore

You should instead use profilestore, its the successor module of profileservice, it’s used by many big games. ProfileStore - Save your player data easy (DataStore Module)

playerstate is literally a wrapper for profilestore

looks like the wrapper module isnt doing a great job…

Well I’ve been using the module for all my games and it’s worked fine. It’s just this one issue

UPDATE: I fixed it by removing a task.wait(0.1)

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