Player.chatted function not working

Here’s a snippet of my script which uses the player.chatted function, it’s an admin script. Whenever the player chat it’s meant to at least print that they chatted, but it doesn’t and the commands don’t work.

game.Players.PlayerAdded:Connect(function(player) -- When a player says something
	player.Chatted:connect(function(msg)
	
	print('chat detected')
	
	local command = string.split(msg, ' ')
	
	local cmd = table.remove(command, 1)
	local arg1 = table.remove(command, 1)
	
	if cmd == '!kick' then--  and Check(player.Name) >= mod and Check(Fill(arg1)) <= Check(player.Name) then

There’s an appropriate “end” structure at the end of the script and there’s no output response.

1 Like

:connect() is deprecated, use :Connect() instead. Also, check where your Script is located.

1 Like

Can you show us the entire script? Also, connect is deprecated. Use Connect instead.

1 Like

What type of LuaSourceContainer is it and where? If you added a print before the Chatted Connection does it print?

1 Like

The script has hundreds of lines, that’s the important part, I’ll switch to Connect and see if that works out.

It’s located on ServerScriptService which I use to make my admin command scripts

Yes, it prints, indicating that the script is running.

1 Like

Are there any errors in the output?

1 Like

Nope, wish I had, those really help sometimes.

1 Like

Ok, I’ve replicated your situation, “chat detected” prints for me. I think the problem lies outside of the code editor, try checking all of the properties of the Script and of all of its ancestors. Check stuff like:

  • Is the Script archivable?
  • Is ServerScriptService archivable?
  • Is the Script enabled?
2 Likes

I think good ol’ roblox is acting up again, since this Covid-19 pandemic I’ve had many scripts break out of nowhere and then fix theirselves, I’ll try to boot up the studio later and it might work. I have literally the same script opened on another place and it works just fine. If it still doesn’t work I’ll keep you guys updated.

2 Likes

Alright, I did more testing and apparently the PlayerAdded function is the problem, I used the print function to print whenever a player joins and it didn’t print. I also used the same print command on my datastore script right after PlayerAdded and it worked, I have no clue on what can be the problem, I tried ChildAdded too but no difference.

1 Like

I really recommend this to be done from the client, it brings a lot of latency especially since the event is called everytime the player chats.

Later on, if you want commands to affect the server, use remote events.

1 Like

That’ll be a big problem to work around with considering I know for sure it works the way it does now, if I use remote events I’ll have to add new security layers to the script and it may even be bypassed by exploiters at some point, I wouldn’t personally trust the client to hold such power, even if I do verification methods hackers always find a way around it.

Basing on what you said, the top of your script runs but the PlayerAdded handler does not. Perhaps you have an infinite loop like a while loop in between?

Okay, can you give me any example where I, as a white hat hacker, can bypass a server check?

I cannot think of one. Sacrificing performance for security is not so much as a sacrifice, it’s a disaster.
Normally, a player will not join your game, thinking ‘Is this secure?’, instead, he will think ‘Why is this lagging so much?’ or ‘Why is it taking so long?’

You may not see it’s impact (unless you debug), until you add more and more performance intensive systems.
However. it’s only my opinion. Do what you think is best. Good luck!

1 Like

If you fire a RemoteEvent with the client, the server can see which player fired it. Because of this, you would only need to check wheter the client that fired the event is an admin or not. It isn’t that hard to implement, either. :slight_smile:

Yeah, I think I’ll do that, I had some bad experiences with using remote events to make admin command scripts but that’s probably because I didn’t had good scripting skills.

I am working on a similar system and it seems like i am having the same issue too…

EDIT: It’s only not working on studio.

I fixed it now, before the PlayerAdded function there were a few other functions like complete names, tool names, item names, etc. Those were corrently enclosed but for some reason they were clogging the script, now that they’re after the PlayerAdded function it works perfectly fine.

1 Like