Why this code dont working, it starts without errors

local Admins = {"SaMerloin", "SaMerloin"}
local Prefix = '!'
game.Players.PlayerAdded:Connect(function(p)
	for i, v in pairs(Admins) do
		if Admins == p.Name then
			p.Chatted:Connect(function(msg)
				if msg == Prefix..'flash' then
					print(1)
				end
			end)
		end
	end
end)```

Your game still using Legacy ChatService (old)? or the new TextChatService?
If its a new baseplate, surely its using TextChatService, and that wont allow the use of Player.Chatted().
Be sure what ChartService you are using.

And use UserIds instead of names:

local Admins = {1324564786, 1564789615} -- "SaMerloin", "SaMerloin"
local Prefix = '!'
game.Players.PlayerAdded:Connect(function(p)
	if table.find(Admins, p.UserId) then
		p.Chatted:Connect(function(msg)
			if msg == Prefix..'flash' then
				warn(1)
			end
		end)
	end
end)
2 Likes

It does not work since you’re comparing a table to a String (name)

You could correct it by replacing Admins with v, however, I would suggest going for a more readable solution. Instead of looping, just check if the player’s name is inside the table using table.find(table, whatToFind)

local Admins = {"Merlonx", "SaMerloin"}
local Prefix = '!'
game:GetService("Players").PlayerAdded:Connect(function(p)
	if table.find(Admins, p.Name) then
		p.Chatted:Connect(function(msg)
			if msg == Prefix..'flash' then
				print(1)
			end
		end)
	end
end)

I would also like to add: It seems you are checking for the DisplayName. I would not suggest doing that since anyone can use (almost) every DisplayName they want. Switch to your username or UserId instead. Merlonx

1 Like

Nah, use only UserID, never UserName or DisplayName. Its possible that any of your admins change the UserName or DisplayName, and you should go back to the code to change it. DSS records same as any special feature for players should be based on UserID

Both options work. However, you’re correct that UserId does not change.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.