Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with simple Custon Admin Command?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago

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

Log in to vote
2
Answered by
Legojoker 345 Moderation Voter
8 years ago

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)

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. Shawnyg 4330 — 8y
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 Perci1 4988 — 8y
Ad

Answer this question