Why isn't the xp or max xp saving but everything else is

im trying to make a level up system and so far its great and everything works, but the xp and max xp (max xp as the amount of xp you need until you level up.) arent saving! I have other things that save perfectly same with the levels, and also yes i am adding the xp on the server not the client.

Heres the small bit of the code where it saves:

	local XP = folder2:FindFirstChild("XP")
	
	datastore:SetAsync(plr.UserId, XP.Value)
	
	local XPmax = folder2:FindFirstChild("XP").max

	datastoremax:SetAsync(plr.UserId, XPmax.Value)

Are you saving the player’s data as a table? If not then it’s better to save the player’s data as a table.

before answering I would like to know what XP is, is it an IntValue? if yes then what is (“XP”).max?

im not sure how to save the players data as a table and i have looked into it and i dont understand it.

the xp and xpmax is a numbervalue

so … XPmax is a child of XP?
like so ?

local XP = smth ??
local XPmax = XP.max ? 
1 Like

yes xpmax is the child of xp in this case

It’s simple really:

local data = {
	XP = (...).Value
	XPMax = (...).Value
	-- etc
}

datastoremax:SetAsync(plr.UserId, data)

data = datastoremax:GetAsync(plr.UserId)

print(data.XP, data.XPMax)
2 Likes

Quick correction would be

	local XP = folder2:FindFirstChild("XP")
	
	datastore:SetAsync(plr.UserId, XP.Value)
	
	local XPmax = XP.max

	datastoremax:SetAsync(plr.UserId, XPmax.Value)
1 Like