Player.Chatted Non-Functional

I tried inserting logical prints in between every line of code seen here, and I have also tested both in game and in test mode. The rest of the code works perfectly without the dependency of this code, however, this piece of code is important to initiate raids.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
--Argument for group requirement
Player.Chatted:Connect(function(Message)
if string.lower(Message) == ":official" then
--Official function
end
end)
end)

By logical I mean prints like: print(Player) or print(Message)

Question: Has Player.Chatted been deprecated?

1 Like

I dont think so, it still works for me and the dev hub does not say that its deprecated. Player | Documentation - Roblox Creator Hub

Perhaps something else is interfering or you have the default chat disabled with SetCore?

Don’t think so

also for commands you can do

local args = string.split(Message)
local command = args[1]
if command == prefix..'kick' then
-- blah
end
2 Likes

The core gui is visible and is never set to false.

I haven’t tried this method for prefixes. However I don’t see how this will fix the function being entirely non-functional for me. It goes from working a week ago to not working after never being touched/changed.

Possibly that PlayerAdded connects after you’ve been added it happened to be in studio try like inGame not studio?

This works! It seems that Roblox would rather you split up prefixes and messages and have them separate. This use to not be the case a week or two ago. :confused: Thank you for the help.

The issue was that your original code was checking if the text was exactly “:official”, rather than checking if it started with “:official”. It’s not about what Roblox wants/would rather have; it’s about what your code functionally does versus what you intend it to do.

2 Likes

So am I stupid or did string.lower(Message) never work?

That just makes the message lowercase, which it did do, it doesn’t trim off the end of “:official whatever args here”

2 Likes

I see now. I guess the reason for my confusion is that I somehow made it work like that before. Thanks for the explanation.

1 Like

After staying up all night I have deduced that this code is foolproof:

game.Players.PlayerAdded:Connect(function(Player)
	--if Player meets requirements then
		Player.Chatted:Connect(function(Message)
			if Message:sub(1,1) ~= "!" then
				return
			end
			local Command = Message:match('%a+')
			local Variables = Message:sub(#Command+2)
			if Command:lower() == "official" and not Official.Value then
				--Pass along argument
			end
		end)
	end
end)
2 Likes