DatastoreService: Would this work?

Okay, this is like my 3rd question about datastore, but here is another question for the community.

I got a :SetAsync function I want to show you.

datastore:SetAsync(player.UserId.."_"..slot, data["Purchases"][EquippedItemType][equippedItem] == "Equipable")

Would that change the value inside of the datastore? Or do I need to store a value in order to fix this problem?

1 Like

It would make the whole entire datastore to that value. There is UpdateAsync() for that, which is similar, and allows to compare data, and replace it with new data, which looks like what you are trying to do

1 Like

What would it look like? Would it be this?

datastore:UpdateAsync(player.UserId.."_"..slot, data["Purchases"][EquippedItemType][equippedItem] == "Equipable")

Here is something I found I could do.

local updatedData = data["Purchases"][EquippedItemType][equippedItem] == "Equipable"		
--datastore:SetAsync(player.UserId.."_"..slot, data["Purchases"][EquippedItemType][equippedItem] == "Equipable")
datastore:UpdateAsync(player.UserId.."_"..slot, function(past)
	return updatedData
end)

If you’re going to do that the there’s no point in using UpdateAsync, that’s just a wasted read request.

I recommend using a simpler solution like ProfileService.