Numerical Variables in tables

  1. I am trying to make a levelling system based on tables, and trying to get a level value from a defined table in a different modular script, basically storing the requiredEXP to level up in a table.

  2. when I get the level, lets say 1 for example, using table.find or iterating the table with for i,v in pairs, it returns nil.

  3. I have tried using some other solutions such as for i = 1, #requiredEXP (table) but it comes out as the same result. Most of the posts are on alphabetical variables in the table, not numerical.

local RequiredEXP = {

	["1"] = 30,
	["2"] = 55,
	["3"] = 83,
	["4"] = 108,
	["5"] = 144,
	["6"] = 183,
	["7"] = 233,

}
	for i,v in pairs(RequiredEXP) do
			local item = RequiredEXP[i]
			if item == LevelData then
				print(item)
			else
				print(item)
			end
		end

--// or
	local LevelData = PlayerDataHandler:Get(plr, "Level")
print(table.find(RequiredEXP, LevelData)

--// or

local REQ = RequiredEXP[LevelData]
print(REQ)
1 Like

Is LevelData a number or string, if it’s a number that’s why it’s returning nil.

its a number
https://gyazo.com/7aff22c254192b53b0bf288d416d63d9

how would i change the LevelData to a string but also keep it so that it records the levelvalue?

local LevelData = PlayerDataHandler:Get(plr, "Level")  -- in here LevelData is a number
local LevelDataStr = tostring(LevelData)  -- convert LevelData to a string for table access

You can do RequiredEXP[tostring(LevelData)] or you can just get rid of the " 's around the numbers in your table.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.