Help with "Invalid argument #1 to 'lower' (string expected got function)"

Hello developers. So I’ve been trying to make a F1 marshall light system, which starts a function when a specific chat is sent. Everything was working correctly, until I’ve started creating the functions themself.
Basically my code was a print after detected specific message, but now I wanted to replace it with functions. Got the “Invalid argument #1 to ‘lower’ (string expected got function)” error.

This is my code:

-- SETTINGS

local GreenFlag = "Green_Flag"; -- Message that sets the flag to Green.
local YellowFlag = "Yellow_Flag"; -- Message that sets the flag to Yellow.
local RedFlag = "Red_Flag";  -- Message that sets the flag to Red.
local VirtualSafetyCar = "VSC";  -- Message that sets the screen to VSC.
local SafetyCar = "SC";  -- Message that sets the screen to SC.

-- LOCALS

local PlayersService = game:GetService("Players");

-- FUNCTIONS
local function GreenFlag()
	script.Parent.Screen.BrickColor = BrickColor.new("Lime green")
end;

local function YellowFlag()
	wait(1.5)
	script.Parent.Screen.BrickColor = BrickColor.new("Bright yellow")
	wait(1.5)
	script.Parent.Screen.BrickColor = BrickColor.new("Really black")
end;

local function RedFlag()
	wait(1)
	script.Parent.Screen.BrickColor = BrickColor.new("Really blue")
	wait(1)
	script.Parent.Screen.BrickColor = BrickColor.new("Really black")
end;
--

PlayersService.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message)
		if string.find(string.lower(Message), string.lower(GreenFlag)) then
			print("GreenFlag")
			GreenFlag()
		elseif string.find(string.lower(Message), string.lower(YellowFlag)) then
			print("YellowFlag")
			YellowFlag()
		elseif string.find(string.lower(Message), string.lower(RedFlag)) then
			print("RedFlag")
			RedFlag()
		elseif string.find(string.lower(Message), string.lower(VirtualSafetyCar)) then
			print("VSC")
		elseif string.find(string.lower(Message), string.lower(SafetyCar)) then
			print("SC")
		end;
	end);
end);

Let me know if anything is unclear.

2 Likes

Thats beacuase the green flag etc are functions. You can either make them return a string or just write “green flag”Etc for each lower thing.

1 Like

I just know that the error says that you did something like that:

string.lower(function)
1 Like

elseif string.find(string.lower(Message), string.lower(YellowFlag)) then

This is not the only line containing an issue, but it should give you the gist of it.
You’re calling string.lower on YellowFlag which was originally a variable but you redefined it to be a function by saying local function YellowFlag().

Change the name of the functions so they won’t be identical to the names of the variables (or vice versa).

1 Like