Invalid Argument #2 (string expected, got nil) can anyone help?

So, im making a admin script for logging the chat of a certain user, but for some reason its giving a strange error on chatted event, can anyone help fix it? its a local script btw

The Line with the error

game.Players[_G.SelectedPlayer].Chatted:Connect(function(message, recipient)

Could you send the whole code? I don’t know what could be wrong with this one line.

Alright, here is it:

local toggled = true

game.Players[_G.SelectedPlayer].Chatted:Connect(function(message, recipient)
	if not toggled then return end

	print(msg)
end)

For now its just a simple print thing for testing

It’s because you did:

print(msg)

Instead of:

print(message)

New code:

local toggled = true

game.Players[_G.SelectedPlayer].Chatted:Connect(function(message, recipient)
	if not toggled then return end

	print(message)
end)

I changed that but the error in the 3rd line continues, its the same error: Invalid Argument #2 (string expected, got nil)

Is _G.SelectedPlayer a string that you set earlier?

1 Like

Yeah it is, its set to my name just for testing

Oh nevermind i found out the error was at a extra line before it i forgot to delete, thanks for the help tho!