Error: attempt to call Instance value (even though its a function)

I’m trying to get a script that can turn a word to a number and I found one on stackoverflow, and I have one module script that contains the numToWord function (IntegerNumberInWords(n)) and another module that contains the wordToNum function (digitize(n_as_text)), but whenever I try to call the numToWord function from the wordToNum function, it errors: ReplicatedStorage.gameModules.WordToNumber:6: attempt to call a Instance value even though it’s a function. The numToWord function also works on the console but not in the wordToNum function.



local IntegerNumberInWords = require(game.ReplicatedStorage.gameModules.NumberToWord)

local function digitize(number_as_text)
	number_as_text = number_as_text:lower():gsub("%W", "")
	for i = 1, 50 do
		if IntegerNumberInWords(i):lower():gsub("%W", "") == number_as_text then
			return i

return digitize



local append, concat, floor, abs = table.insert, table.concat, math.floor, math.abs
local num = {'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven',
	'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'}
local tens = {'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'}
local bases = {{floor(1e18), ' quintillion'}, {floor(1e15), ' quadrillion'}, {floor(1e12), ' trillion'},
{floor(1e9), ' billion'}, {1000000, ' million'}, {1000, ' thousand'}, {100, ' hundred'}}

local insert_word_AND = false  -- 101 = "one hundred and one" / "one hundred one"

local function IntegerNumberInWords(n)
	-- Returns a string (spelling of integer number n)
	-- n should be from -2^53 to 2^53  (-2^63 < n < 2^63 for integer argument in Lua 5.3)
	local str = {}
	if n < 0 then
		append(str, "minus")
	n = floor(abs(n))
	if n == 0 then
		return "zero"
	if n >= 1e21 then
		append(str, "infinity")
		local AND
		for _, base in ipairs(bases) do
			local value = base[1]
			if n >= value then
				append(str, IntegerNumberInWords(n / value)..base[2])
				n, AND = n % value, insert_word_AND or nil
		if n > 0 then
			append(str, AND and "and")   -- a nice pun !
			append(str, num[n] or tens[floor(n/10)-1]..(n%10 ~= 0 and '-'..num[n%10] or ''))
	return concat(str, ' ')

return IntegerNumberInWords

Line 6 (the line that’s erroring) is print(IntegerNumberInWords(i)), but when I remove that, line 6 errors again, but it’s IntegerNumberInWords(i):lower():gsub("%W", "") then.

Again, when I run numToWord on the console it doesn’t error at all and outputs a string, as expected.

I just realized after adding the credits, line 6 is still erroring, even though line 6 is now a comment. So, after a restart of roblox studio, it now works. I guess it was just a bug with studio.

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