Need help with my function giving an error

This function I use is to change a string like 10M into a number like 10000000

_G.abbreviationValues = {
	["K"] = 1000;
	["M"] = 1000000;
	["B"] = 1000000000;
	["T"] = 1000000000000;
	-- and so on... you can fill the rest in if you need to
};

_G.complicateNumber = function(str:string)
	print(str)
	if tonumber(str) then
		return tonumber(str)
	end
	local number, abbreviation = str:match("^([%d.]+)(%a)$");
	if number and abbreviation then
		local value = _G.abbreviationValues[abbreviation:upper()];
		if value then
			return value * tonumber(number);
		end
	else
		
		error("Invalid abbreviation:" .. str);
	end
end

when i try to call it like

print(_G.complicateNumber("10m"))

it returns

This is all in a server script in serverscriptservice

Why dont you just have this as a function inside of a module script?

I don’t see how it would make a difference, but im new to using _G and ModuleScripts so what can I say.

Would having it in a modulescript make any difference?

Edit: well adding it into a modulescript all worked so thats nice

1 Like

what type of script are you calling the function from?

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