.Changed() for tables?

I check did a player reach new level every time I add XP to the player like this:

function PlayerDataApi.addXP(player, xp)
	local dataValue = playerDataFolder:FindFirstChild("Data_"..tostring(player.UserId))
	if dataValue ~= nil then
		local data = HttpService:JSONDecode(dataValue.Value)
		data.XpAmount = data.XpAmount + xp

		if data.XpAmount == Levels.getXpRequired(data.Level + 1) then
			data.XpAmount = 0
			data.Level = data.Level + 1
		elseif data.XpAmount > Levels.getXpRequired(data.Level + 1) then
			data.XpAmount = data.XpAmount - Levels.getXpRequired(data.Level + 1)
			data.Level = data.Level + 1
		end

		dataValue.Value = HttpService:JSONEncode(data)
	end
end

(That code is in a ModuleScript and I always use that module script to add XP to players)

2 Likes