Chat Service Runner: nil with lower

Hi, My problem is when I try to get the speaker it returns with this error:
ServerScriptService.ChatServiceRunner.ChatService:169: attempt to index nil with 'lower'

My code:

	plr.Chatted:connect(function(msg)
		if string.lower(msg) == "/e rights" then
			local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
			local speaker = ChatService.GetSpeaker(string.lower(plr.Name))
			speaker:SayMessage("TEST", "All")
		end
	end)
end)

We need more information. What is this code supposed to do, exactly?

It is suppose to make the user say TEST when the user says /e rights

Now that I look back on this, I believe that the problem is with your chatted function. What is the ‘plr’ value declared as? Where is it declared?

I see a few things wrong with this code, if you can clarify or if this helps:

  • Is GetSpeaker a function or otherwise? I don’t recognize the method. If so, I don’t think you should be calling the player’s name as a string and keep it as the instance.
  • If you’ve copied a script from a built-in Roblox script, you shouldn’t have done that. What you’re trying to do should be achieved via a normal script.

before that i have game.Players.PlayerAdded:Connect(function(plr)

  • Is GetSpeaker a function or otherwise? I don’t recognize the method. If so, I don’t think you should be calling the player’s name as a string and keep it as the instance.
    Ive checked the api.
  • If you’ve copied a script from a built-in Roblox script, you shouldn’t have done that. What you’re trying to do should be achieved via a normal script.
    I dont copy scripts.

Ive checked the api.

Mind linking the page?

I dont copy scripts.

I was asking if you copied a script that Roblox requires to run ChatService. If not, the problem is not in that area.

Additionally, if you’re trying to get the speaker, you can just call plr directly and use that for your speaker variable.

plr.Chatted:connect(function(msg)
  print(msg)
  print(string.lower(msg))

Have you attempted to print the variables? can you attempt this and see what it returns?

Are you overwriting string as your own nil variable somewhere else in the script?

3 Likes