Basic Admin Commands


  • Admin Commands are pretty simple to set up.

    Today we're going to be learning how to use module scripts, and how to manipulate strings.

    We're going to be opening a ModuleScript inside ReplicatedStorage. I'll name the ModuleScript "AdminCommands".

    0_1555557204033_ModuleScript1.png

    As you can see in our ModuleScript code, we have a function in here. With this function, we can access the "CheckAdmin" function in any script if they're using "require".

    In the function what we're doing is looping through the admins table to see if the player's UserId is inside the table. If that is true, we'll return true. If not, we return false. In our "Admins" table we store UserIds of the Admins we want.

    Now we'll be moving on to LocalScripts. We'll create a LocalScript inside StarterPlayerScripts.

    0_1555558348180_ModuleScript1.png

    Inside the code we have an event, and a couple of variables. We have the "AdminCommands" ModuleScript, the player, and the "isAdmin" command.
    We're using the AdminCommands ModuleScript to use our admin commands since that's where we'll be using our commands. The checkAdmin command is used to check if the player is an admin or not.

    We use the Player for an event, which is the Chatted event. This is fired whenever the player chats. We use Message for reference for the actual message.

    We check "isAdmin", and if that is false we end the code immediately from there. If not, it continues.

    We'll cut up the message into the first eight characters. If they are equal to ":Explode" then we find the targetedPlayer.

    The targetedPlayerName is basically the name of said player. We'll cut up the message again, however we'll cut it up into the tenth character all the way up to the Message's length. Now we use the targetedPlayer variable to get the targetedPlayer by finding the player using the target's name. If that player does exist, we use an Explode command in the AdminCommands module script. However, we haven't done that yet. That's what we'll be doing next.

    Inside the ModuleScript's code we'll be doing the following:

    0_1555558161311_ModuleScript2.png

    In the code we have the admin command. What we're doing over here is creating an Explosion and putting the explosion's position into the target's HumanoidRootPart position. Afterwards we'll put the parent of the explosion into the workspace so it can be seen and affect the target.

    Now let's test it out!

    This is the end result for me (Sorry for bad quality, it got compressed somehow.)

    So what did we learn today?

    String manipulation (string.len and string.sub)
    Events (Player.Chatted)
    Module Scripts(require, etc.)
    Tables (Admins,Indexing,etc.)

    Feedback would be greatly appreciated. Good luck!


  • First off, don't post screenshots of the code. This makes it impossible to copy and paste it and make necessary changes. Your string colour is so dark I can't even read it.

    Second off, your CheckAdmin function is going to immediately return false if a player joins but their UserId is not first in the list. Even if it's an admin.

    Also, the IDs should already be a number, calling tonumber is just redundant.

    function module.isAdmin(client) --// 'is' is better than 'check'
        for _, id in ipairs(Admins) do
            if (rawequal(client.UserId, id)) then
                return true;
            end
        end
        return false;
    end
    

    If the return false; statement is reached that is because the above was not fulfilled; the player is not an admin.

    Also, you should not be handling admin commands client sided. An exploiter can manipulate the requirements this way.

    Finally, you are not using len correctly. It is used string.len(s) or s:len(). Again, this is a number, you don't need to call tonumber. Either way, don't use it: we have the unary length operator #. Use #s.

    So what did we learn today?
    Events (Player.Chatted)
    Module Scripts(require, etc.)
    Tables (Admins,Indexing,etc.)

    Your thread does not revolve around events, module scripts or tables. You listened for events, yes, but your thread isn't about events! Same for everything else.


  • This post is deleted!
Log in to reply
 

Looks like your connection to Scripting Helpers was lost, please wait while we try to reconnect.