Level Leaderstats problem

For some reason when I try to call the level leaderstats it does not work on a leaderboard and says I can to call two datas. Why is that?
image

DataStore2.Combine("MasterKey","Gold","Level")

game.Players.PlayerAdded:Connect(function(plr)
	local datastores = {
		["Gold"] = DataStore2("Gold", plr),
		["Level"] = DataStore2("Level", plr)
	}
	local datas = {
		["Gold"] = datastores["Gold"]:Get(),
		["Level"] = datastores["Level"]:Get()
	}
	local folder = Instance.new("Folder",plr)
	folder.Name = "leaderstats"


	local gold = Instance.new("IntValue", folder)
	gold.Name = "Gold"

	local level = Instance.new("NumberValue", folder)
	level.Name = "Level"


	if datas["Gold"] ~= nil then
		gold.Value = datas["Gold"]
	else
		gold.Value = 100
	end
	if datas["Level"] ~= nil then
		level.Value = datas["Level"]
	else
		level.Value = 0
	end
	gold.Changed:Connect(function()
		datastores["Gold"]:Set(gold.Value)
	end)
	level.Changed:Connect(function()
		datastores["Level"]:Set(level.Value)
	end)

end)

Double is simply a number with decimals. You can multiply by 10, 100, etc to remove the decimals and then divide to get the real number.

0.4 * 10 = 4, save it as this
4/10 = 0.4, once loaded convert it

You can also just use tostring() and save it as a string and then once the value is loaded from the data store you can use tonumber()

Very helpful tip:
Instead of

        if datas["Gold"] ~= nil then
		gold.Value = datas["Gold"]
	else
		gold.Value = 100
	end
	if datas["Level"] ~= nil then
		level.Value = datas["Level"]
	else
		level.Value = 0
	end

You can just do

gold.Value = datas["Gold"] or 100 -- if the first doesn't exist, it will assign the second
--[[ this is the shortcut of the ternary operator, which would you look like

gold.Value = datas["Gold"] and datas["Gold"] or 100, 
between the = and the "and" is the condition (can use ==, <, >, >=, <=), 
after the and is the value if true, after the or is the value if false, it will assign it to the variable
--]]

I think I understand what you mean at the bottom, but I still do not understand the double part.

There are multiple types of numbers

Integer (aka Int) → whole numbers, Z in maths, 1, 2, 3, 4, -1, -150, 12731, etc

Float or Double → Real numbers, R in maths, anything with decimals → 1.5, 1.51, -1.54654664

Doubles are much heavier in terms of storage than integers. Because in doubles, there’s a slight imprecision, basically it means that 1.5 is seen as 1.5000000000000000000000000000000000000000000000000000001 for the computer (not specifically that amount of 0s)

So, you just need to convert the numbers to either Strings or Integers before storing them

If you save as Integers, multiply the 10^n, enough to have no decimals. 0.4 needs x10, 0.04 x 100, 0.004, x1000, etc. So just use the precision of your value to determine what to multiply with
After the data is loaded from the datastore, simply divide it by that same number, and you get your float/double

If you choose to save as String, then just use tostring(number) before storing it and use tonumber(string) after loading it

But why is this only for level that it does this?

Maybe you accidentally stored it once as a double (maybe added a decimal by mistake) and now even if you keep adding whole numbers it’s going to stay a float forever.

Do print(typeof(level.Value)) and tell me what it outputs


I think I know why but this is only for me.

Maybe you accidentally added a decimal once and now it’s like that forever. You can do math.floor or math.ceil to round the number, though I’m not sure if it’ll convert it to integer, but think so.
Add that to the script, then join and leave so the data saves, then you can delete that from the script

So where do I use this, because I do not set the players level anywhere. I just changed it to 1740 from the developer console.

level.Changed:Connect(function()
		datastores["Level"]:Set(level.Value)
	end)

Here you set it, you can just use :set(math.floor(level.Value))

Okay so like this?


DataStore2.Combine("MasterKey","Gold","Level")

game.Players.PlayerAdded:Connect(function(plr)
	local datastores = {
		["Gold"] = DataStore2("Gold", plr),
		["Level"] = DataStore2("Level", plr)
	}
	local datas = {
		["Gold"] = datastores["Gold"]:Get(),
		["Level"] = datastores["Level"]:Get()
	}
	local folder = Instance.new("Folder",plr)
	folder.Name = "leaderstats"


	local gold = Instance.new("IntValue", folder)
	gold.Name = "Gold"

	local level = Instance.new("NumberValue", folder)
	level.Name = "Level"


	gold.Value = datas["Gold"] or 100
	level.Value = datas["Level"] or 0
	
	gold.Changed:Connect(function()
		datastores["Gold"]:Set(gold.Value)
	end)
	level.Changed:Connect(function()
		datastores["Level"]:Set(math.floor(level.Value))
	end)

end)

Yeah do that once, join, play something to increase your level, leave and remove that part from the script

Can I leave it there forever so that it never does that again?

You can of course, but you might want to use math.ceil so it rounds upwards instead of downwards.

But how does this have to do with the global leaderboard? Oh wait I think you misunderstood. It does not show on a global leaderboard and shows double is not used in datastores.