ServerScriptService.Script:15: attempt to call a nil value - String-Calculator Script

Hey! I’m making a String Calculator and I’m stuck with this error: ServerScriptService.Script:15: attempt to call a nil value

Script:

	local mathFunctions = {
		["Add"] = function(number1, number2)
			return number1 + number2
		end;
		["Multiply"] = function(number1, number2)
			return number1 * number2
		end;
		["Divide"] = function(number1, number2)
			return number1 / number2
		end;
	}
	----------------------------------------------------
	local function calculate(number1, mathOperation, number2)
		local lower = string.lower(mathOperation)
		return tonumber(mathFunctions[lower](number1, number2))
	end
	----------------------------------------------------
	print(calculate(5, "Add", 5))

Line 15:

return tonumber(mathFunctions[lower](number1, number2))

Thank you!

Your math functions are capitalized but you lowercased the call string. Change

["Add"] = function(number1, number2)
	return number1 + number2
end;
["Multiply"] = function(number1, number2)
	return number1 * number2
end;
["Divide"] = function(number1, number2)
	return number1 / number2
end;

to

["add"] = function(number1, number2)
	return number1 + number2
end;
["multiply"] = function(number1, number2)
	return number1 * number2
end;
["divide"] = function(number1, number2)
	return number1 / number2
end;
3 Likes

Casing error. You lowercased the value "add" but not the index key "Add".

2 Likes