SetAsync removing data from dictionary

I have a lot of data that is similar but has one part different so I tried making for loop to go through and add to the playerData.

local playerData = {}
	
	for i, tower in pairs(tycoon.BallTowers:GetChildren()) do
		PlayerData[tower.Name] = {
			Damage = tower.Damage.Value,
			Speed = tower.Speed.Value,
			Quantity = tower.Quantity.Value,
		}
	end

However, it’s not saving and I have no idea why. Printing before saving it shows me all the values I added. But printing after saving all the values are gone. I’m extremely stumped right now.

print(PlayerData)
		playerDataStore:SetAsync(tostring(playerUserId), playerData)
		print(PlayerData)

put it in a pcall and see if there are errors.

1 Like

i left it out but it is already inside one

1 Like

Any errors? Cause this sounds really strange

Which data is being removed from the dictionary?

Edit: Nvm, I see

no errors at all. If I hard code the dictionary it works but I’m trying to avoid that.

Ok lol restarting my studio fixed it but now using getAsync doesn’t return the right dictionary bro I’m so lost

When loading playerData now I’m basically getting the same issue. for example if I want to get playerData.Fire.Speed it says Fire is nil.

But if I print playerData on the same line I see Fire and its speed is 2

You’re setting playerData again as the value to save which has been defined as an Empty Table. So, it’s only going to save an empty table every time. This is why your values are Nil when you print them after setting your data.

remove the playerData value from the SetAsync property and see if this changes anything