Attempt to call a instance value

Module Script:

local module = {}
local abvs = {
	"", 
	"K", -- 4
	"M", -- 7
	"B", -- 10
	"T", -- 13
	"Qd", -- 16
	"Qn", -- 19
	"Sx", -- 22
	"Sp", -- 25
	"O", -- 28
	"N", -- 31
	"de", -- 34
	"Ud", -- 37
	"DD", -- 40
	"tdD", -- 43
	"qdD", -- 46
	"QnD", -- 49
	"sxD", -- 52
	"SpD", -- 55
	"OcD", -- 58
	"NvD", -- 61
	"Vgn", -- 64
	"UVg", -- 67
	"DVg", -- 70
	"TVg", -- 73
	"qtV", -- 76
	"QnV", -- 79
	"SeV", -- 82
	"SPG", -- 85
	"OVG", -- 88
	"NVG", -- 91
	"TGN", -- 94
	"UTG", -- 97
	"DTG", -- 100
	"tsTG", -- 103
	"qtTG", -- 106
	"QnTG", -- 109
	"ssTG", -- 112
	"SpTG", -- 115
	"OcTG", -- 118
	"NoAG", -- 121
	"UnAG", -- 124
	"DuAG", -- 127
	"TeAG", -- 130
	"QdAG", -- 133
	"QnAG", -- 136
	"SxAG", -- 139
	"SpAG", -- 142
	"OcAG", -- 145
	"NvAG", -- 148
	"CT", -- 151
	"TaCG", -- 154
	"AnTG", -- 157
	"YX", -- 160
	"YaZQ", -- 163
	"YXZ", -- 166
	"NoEV", -- 169
	"KoTG", -- 172
	"TrAG", -- 175
	"e178",  -- 178
	"e181", -- 181
	"e184", -- 184
	"e187", -- 187
	"e190", -- 190
	"e193", -- 193
	"e196", -- 196
	"e199", -- 199

	"∞"; -- ok
}

module.abbreviate = function(number)
	for i =1, #abvs do
		if number < 10 ^ (i * 3) then
			if abvs[i] == "∞" then
				return "∞"
			else
				return math.floor(number / ((10 ^ ((i-1) * 3)) / 100)) / (100)..abvs[i]
			end
		elseif tostring(number) == "inf" then
			return "∞"
		end
	end
end
return module

Script

local abbreviate = require(script.Parent.AbbreviateModule)
print(abbreviate(lvl.Value))

Attempt to call a instance value i tried

tonumber(lvl.Value)

lvl is a numberValue inside player leaderstats

Looks like you are trying to call the module as a function. There are a number of ways to do what it looks like you are trying there, but the basic way is like this:

local AbbreviateModule = require(script.Parent.AbbreviateModule)
local ans = AbbreviateModule.abbreviate(lvl.Value)
print(ans)
1 Like

An alternative to above solution is to change the module to return a function directly:

return function(number)
	--code
end

And not have the module = {} or module.abbreviate at all. Unless you plan to add more functions in the module then above solution is in most cases the best.