How do I make it so when a msg is chatted by an Admin, it fires an event?

What I’m attempting to achieve is when a player who has a name of someone on the admin list, it will allow the code to run through if the message of DDD is typed by an admin.
So like this, if a player is an admin and they say “DDD” then the Event will fire.

I’ve looked at the Chatted page on the ROBLOX Wiki/Developer Page and I’ve tried looking on the devforum and I have no idea why this isn’t working. I feel like it’s something simplistic and I just keep missing it.

I don’t know what the error is so I haven’t been able to do much edits. I’ve tried changing the admin value but nothing happens, i’ve tried a for pair, nothing unless I did it wrong. I’ve tried rewording it and it did nothing. The script is below, thank you for any help you can give me. Also yes the event does work as I have it programmed to a GUI Button.

--Made By MillerrIAm
-----------Variables-----------
Event = game.ReplicatedStorage.Extras.BellEvent
plr = game.Players
----------- Messages -----------
msg1 = "DDD" 
msg2 = "Ring the bell."
----------- Admins -----------
admins = {["MillerrIAm"] = true; ["NemesisY2J"] = true; ["Sonicxman"] = true;["Dewwy5280"] = true}
-----------Main Code-----------
plr.LocalPlayer.Chatted:Connect(function(plr,msg)
	if admins[plr.Name] then
		if msg == msg1 then
			Event:FireServer("Ring the bell!")
		end
	end
end)
if admins[plr.Name] then

end

you need to index a table

That did not work but thank you for reminding me to fix this! Any other ideas? No errors pop up.

You do not have to put ["admin"]=true You can just put local admins = {"roblox","admin"}

1 Like

Im fairly certain you can check if the player is a admin when they join server-side, then hook a .Chatted Event to the player, and then you don’t have to fire remotes.

Edit: I just realized your keeping the list of admins on the client, which can easily be manipulated by exploiters. You can view the code at this place to see how it should look Admin command example - Roblox.

3 Likes

Oh okay so my goal is for when a message is sent, it fires an event as it controls a GUI Tween. That’s why I have it firing an event. If you have a discord, I can show you what i’m attempting to do. On-top of that, you are right… you can check to see if a player is an admin through a server script I just never really tested it as I had other goals but I’ll look into that. I still would like to ask if you could give me a little help with my main issue, I am VERY NEW to chat commands and such. What it does is if an admin says msg1 then it fires the event that controls the GUI. The Event works perfectly fine, same with the script, how I know is i have it programmed with a button but I want to control it with a chat message instead.

oh thank you! I wish I would of known that two months ago lol, that would of helped me incredibly although i will continue to use my version unless I can do something different inside of a ServerScript.

1 Like

My disc is Vivid#4585 if I have time tommorow or during this week I’d be glad to help you out.

1 Like

Wrong. OP’s code is indexing the player name as the table key. Your code will index the “roblox”, “admin” with keys 1 and 2.

This is not the same as local admins = {["roblox"] = true, ["admin"] = true} as that code is using "roblox" as the key and the value is true.

Instead of doing [“username”] = true, you can just do this:

admins =
{
   "MillerrIAm";
   "NemesisY2J";
   "Sonicxman";
   "Dewwy5280";
}

The reason why is because you can just do this:

plr.LocalPlayer.Chatted:Connect(function(plr,msg)
	if table.find(admins, plr.Name) then
		if msg == msg1 then
			Event:FireServer("Ring the bell!")
		end
	end
end)

Oh, by the way, you’re calling the value plr when you’re doing localplayer. Msg is returned nil due to plr being the message. Instead, change it to:

plr.LocalPlayer.Chatted:Connect(function(msg)

Since no one here has really fixed OP’s issue, here is what you need to do.

plr.LocalPlayer.Chatted:Connect(function(plr,msg)

This code is incorrect. The Chatted callback will only provide the msg as you already know what player you are trying to detect the chat from: plr.LocalPlayer

After you fix that part plr.Name will be invalid. This is because it will index game.Players.Name which is not what you want. You want to instead change it to game.Players.LocalPlayer.Name. With your code, you can use plr.LocalPlayer.Name.

After doing these 2 fixes, your code will run fine.

2 Likes

May I point out in passing that msg1 is defined as DDD not “Ring the Bell”

This system is easily exploitable. All the exploiter has to do it change your code to make them an admin and be able to use all the commands.

I’d recommend listening for the .Chatted event on the server for extra security, as well as removing the need for remotes.

You can hook the .Chatted event like this:

game:GetService("Players").PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(msg)

    end)
end)
3 Likes

Ring The Bell! is what I named my value in my event.

I just meant that the variable named msg1 is set to DDD and the if msg == msg1 implies that msg1 contains “Ring the bell”.
Sorry if I confused you.
Not important just a mention.

if the variable msg1=DDD
then if msg==msg1 means the msg is = to DDD
edit–I get it, but you reply was really confusing

1 Like