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".
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.
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:
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!
So what did we learn today?
String manipulation (string.len and string.sub)
Module Scripts(require, etc.)
Feedback would be greatly appreciated. Good luck!