Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Check for certain player? (And how can i check if it chatted certain words)?

So.

Ive tried stuff like

local plr = game.Players.LocalPlayer

local admin = {"name1", "name2"} -- etc

if plr.Name == admin then
	script.Parent.Open.Visible = true
else
	script.Parent:Destroy()
end)
-- this script is the child of the CoreGUI thing

I do see my flaws, for example, i dont use V_i in pairs or something like that.

Only i am still new to coding. Sooo im basicly clueless.

And meanwhile im here, i also wanna know. How can i check if that "Admin" chatted a certain text?

example:

admin = "myname", "myfriend", "etc"

plr = game.Players.LocalPlayer

if plr.Name = admin then
	plr.Chatted "/e WORD" then--how does this work? i dont know lol
	
	print("get noob")
end)

Something like that. Im pretty sure that won't work.

So basicly an admin command thing i guess

Thanks in advance!

2 answers

✓ Accepted answer
local Players = game:GetService("Players")

local AdminList = { -- Add your desired usernames here.
	'hexwulf';
	'joemamma';
}

Players.PlayerAdded:Connect(function(Player) -- when player is added
	Player.Chatted:Connect(function(Message) -- when player chats
		if table.find(AdminList, Player.Name) then -- Checks if in table
			if Message == '!whatever' then -- your command
				print(Message) -- do whatever
			end
		end
	end)
end)

Hope this helps, also make this a server script somewhere in workspace or ServerScriptService.

You can use table.find() to avoid loops and chatted events can be used on the server.

Client(localscript):

local Admins = {"name1", "name2", "name3"}
local Player = game.Players.LocalPlayer


if table.find(Admins,Player.Name) then --Checks if Player is admin
	Player.Chatted:Connect(function(msg) --Chatted event (returns the message)
	    if msg == "/e WORD" then --Checks if message is one that you are looking for
			print("get noob") --Prints
		end
	end)
end

Server(script)

local Admins = {"name1", "name2", "name3"}

game.Players.PlayerAdded:Connect(function(Player)--Attaches code below to players
	if table.find(Admins,Player.Name) then--Checks if Player is admin
		Player.Chatted:Connect(function(msg)--Chatted event (returns the message)
	    	if msg == "/e WORD" then--Checks if message is one that you are looking for
				print("get noob") --Prints
			end
		end)
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.