Can't find player name in the table

my goal is to find player name in the moderator table and then if he is staff then if the message is… then it will teleport to the second player. i don’t know why my table not work(no errors)

local moderator = {"artum669","straff"}

local Players = {}


game.Players.PlayerAdded:Connect(function(player)
	
	for i,v in pairs(game.Players:GetPlayers()) do
		table.insert(Players,v)
	end
	
	local staff = table.find(moderator,player.Name)
	local OtherPlayer = table.find(Players,player)
	
	print(staff)
	player.Chatted:Connect(function(message)
		if player.Name == staff then
			print("staff")
			if message == "/tp "..OtherPlayer then
				staff.Character.HumanoidRootPart.CFrame = CFrame.new(OtherPlayer.Character.HumanoidRootPart.CFrame)
			end
		else
			print("not staff")
		end
	end)
end)

the output of the print(staff) is = 1

1 Like

Table.find returns the index in which the value is found in the table. So it would be printing 1.
In your code your checking if the player name is 1. Which it obviously isn’t.

soo how i can find moderator name from table
as you undarstand i need only certain people use the command

Yes of course. So you can try something like this:

local moderator = {"artum669","straff"}

game.Players.PlayerAdded:Connect(function(player)
	local staff = table.find(moderator,player.Name)

	if staff then
		player.Chatted:Connect(function(message)
			-- YOUR CODE HERE (THE PLAYER TYPING IS STAFF)
		end)
	end
end)
3 Likes