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

Help with simple Custon Admin Command?

Whoever is an admin and if they say "Kick all players" then it should kick all players, it does not work. :(

Admins = {"PreyStar"} --Only person that could say remove and does the command

game.Players.PlayerAdded:connect(function(Player)
	Player.Chatted:connect(function(Msg, Person)
		if Person == (Admins[1]) then
			print 'Worked?' --Does not print!!!!
			if Msg == "Kick all players" then
				for i,v in pairs (game.Players:GetChildren()) do
					v:Kick() --I wanna kick the players if an admin says the msg.
				end
			end
		end
	end)
end)

1 answer

✓ Accepted answer

In line 5 of this code block, Person should be Person.Name since you're identifying a string value. Also, I would personally recommend that you connect the listening event AFTER the if statement because you don't need the event to fire every time a non-admin chats.

Admins = {PreyStar = true, Player1 = true} --Only people that can use commands.

game.Players.PlayerAdded:connect(function(Player)
	if Admins[Player.Name] then
		Player.Chatted:connect(function(Msg, Person)
			print 'Worked?'
			if string.lower(Msg) == "kick all players" then
				for i,v in pairs (game.Players:GetChildren()) do
					v:Kick() -- Kick the players if an admin says the msg, including myself.
				end
			end
		end)
	end
end)

2 comments

1

Just a little tip, it's better to use :GetPlayers() rather than :GetChildren() in this case. If an object that wasn't a "Player" was in Players, the script would error, causing not all players to be kicked. Also, you don't need to put = true on line 1. Just putting quotes around the name will do.

0

@Shawnyg, You're right on the first point, but your second point is wrong. When using brackets, you have to give a table's key, not its value. table = {"a", "b"} print(table["a"]) --> nil

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