Intro
Hi there! It’s time for another tutorial! Today we’re going to do some scripting! We’re going to make an admin-style system, with 4 commands. Now, that may not seem like a lot, but I’m going to be teaching you a lot with scripting as we do this. Remote Events, Core GUIs, the Chat Service, all the good stuff. Anyways, let’s get started!
Advanced vs. Beginner
Today’s commands were supposed to extremely simple to make it easier for beginners to understand, but after lots of feedback, I have decided to split the tutorial. There is the less complex, longer code, or there is the more complex, more efficient code. I’ll leave the choice up to you!
Simple
If you want to see the code we are doing today, click below!
Code
ServerScript
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
if message == "/kick" then
game.ReplicatedStorage.KickQuestion1:FireAllClients()
player.Chatted:Connect(function(message)
local players = game:GetService("Players")
local kickedPlayer = players:FindFirstChild(message)
game.ReplicatedStorage.KickQuestion2:FireAllClients()
player.Chatted:Connect(function(message)
kickedPlayer:Kick(message)
game.ReplicatedStorage.KickSuccess:FireAllClients()
end)
end)
end
if message == "/speed" then
game.ReplicatedStorage.SpeedQuestion:FireAllClients()
player.Chatted:Connect(function(message)
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
humanoid.WalkSpeed = message
game.ReplicatedStorage.SpeedSuccess:FireAllClients(message)
end)
end
if message == "/kill" then
game.ReplicatedStorage.KillQuestion:FireAllClients()
player.Chatted:Connect(function(message)
local killPlayer = game.Players:FindFirstChild(message)
local killCharacter = killPlayer.Character
local human = killCharacter:FindFirstChild("Humanoid")
human.Health = 0
game.ReplicatedStorage.KillSuccess:FireAllClients()
end)
end
if message == "/teleport" then
game.ReplicatedStorage.TeleportQuestion:FireAllClients()
player.Chatted:Connect(function(message)
local character = player.Character
local HRP = character:FindFirstChild("HumanoidRootPart")
HRP.CFrame = CFrame.new(Vector3.new(message))
game.ReplicatedStorage.TeleportSuccess:FireAllClients()
end)
end
end)
end)
LocalScript in StarterPlayerScripts
game.ReplicatedStorage.KickQuestion1.OnClientEvent:Connect(function()
local StarterGui = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
StarterGui:SetCore("ChatMakeSystemMessage", {
Text = "Who would you like to kick?";
Color = Color3.fromRGB(255, 255, 255); --Chat message color, defaults to white
Font = Enum.Font.SourceSansBold; --Chat message font, defaults to SourceSansBold
TextSize = 18 --Text size, defaults to 18
})
end)
until Success
end)
game.ReplicatedStorage.KickQuestion2.OnClientEvent:Connect(function()
local StarterGui = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
StarterGui:SetCore("ChatMakeSystemMessage", {
Text = "What were they doing?";
Color = Color3.fromRGB(255, 255, 255); --Chat message color, defaults to white
Font = Enum.Font.SourceSansBold; --Chat message font, defaults to SourceSansBold
TextSize = 18 --Text size, defaults to 18
})
end)
until Success
end)
game.ReplicatedStorage.KickSuccess.OnClientEvent:Connect(function()
local StarterGui = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
StarterGui:SetCore("ChatMakeSystemMessage", {
Text = "Successfully Kicked!";
Color = Color3.fromRGB(255, 255, 255); --Chat message color, defaults to white
Font = Enum.Font.SourceSansBold; --Chat message font, defaults to SourceSansBold
TextSize = 18 --Text size, defaults to 18
})
end)
until Success
end)
game.ReplicatedStorage.SpeedQuestion.OnClientEvent:Connect(function()
local StarterGui = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
StarterGui:SetCore("ChatMakeSystemMessage", {
Text = "What walkspeed do you want?";
Color = Color3.fromRGB(0, 255, 255); --Chat message color, defaults to white
Font = Enum.Font.SourceSansBold; --Chat message font, defaults to SourceSansBold
TextSize = 18 --Text size, defaults to 18
})
end)
until Success
end)
game.ReplicatedStorage.SpeedSuccess.OnClientEvent:Connect(function(Event)
local StarterGui = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
StarterGui:SetCore("ChatMakeSystemMessage", {
Text = "Successfully changed walkspeed to "..Event;
Color = Color3.fromRGB(0, 255, 255); --Chat message color, defaults to white
Font = Enum.Font.SourceSansBold; --Chat message font, defaults to SourceSansBold
TextSize = 18 --Text size, defaults to 18
})
end)
until Success
end)
game.ReplicatedStorage.KillQuestion.OnClientEvent:Connect(function()
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "Who would you like to kill?";
Color = Color3.fromRGB(255, 0, 0);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end)
game.ReplicatedStorage.KillSuccess.OnClientEvent:Connect(function()
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "Successfully killed player!";
Color = Color3.fromRGB(255, 0, 0);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end)
game.ReplicatedStorage.TeleportQuestion.OnClientEvent:Connect(function()
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "Where would you like to go?";
Color = Color3.fromRGB(255, 0, 255);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end)
game.ReplicatedStorage.TeleportSuccess.OnClientEvent:Connect(function()
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "Successfully teleported!";
Color = Color3.fromRGB(255, 0, 255);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end)
Setup
To make this system, you’ll need two scripts, and a lot of remote events. Add one Server Script into ServerScriptService, mine will be named ChatHandler. Add a Local Script into StarterPlayerScripts, which can be found within StarterPlayer. Now, for the events. We will need them all in ReplicatedStorage. Here is a screenshot of all of them.
These will all be used in a command, believe it or not. Well, that’s it for setup! Let’s actually start scripting!
Scripting
Before we just jump into some advanced commands, let’s set up our script with a few simple lines of code:
game.Players.PlayerAdded:Connect(function(player)
--All new code will be found in here
end)
This is just a simple code to get the “local player” in a ServerScript. When the Remote Event, PlayerAdded, is fired, this script will connect it to a function, with the parameter of player
.
Now, we need the player
to chat in order for actual commands to run, so let’s add another function.
game.Players.PlayerAdded:Connect(function(player)
--All new code will be found in here
player.Chatted:Connect(function(message)
--We will now check what "message" is
end
end)
Okay, this new addition basically connects the player
's Chatted
event to a function, with the parameter message
, which we can now check what it is. Let’s add four different if statements
to the code.
game.Players.PlayerAdded:Connect(function(player)
--All new code will be found in here
player.Chatted:Connect(function(message)
--We will now check what "message" is
if message == "/kick" then
--kick command here
end
if message == "/kill" then
--kill command here
end
if message == "/speed" then
--speed command here
end
if message == "/teleport" then
--teleport command here
end
end
end)
So we just added 4 options for message
to be. It can be typed as anything, but the script will only run further if it is either /kick
, /kill
, /speed
, or /teleport
. So, our script is now setup for the commands, now let’s start scripting them!
/Kick
This is a pretty common command, used commonly for moderation systems. We will have ours work similar to a discord bot, in the fact that the system will respond with questions. Let’s start adding code to the first if statement
.
if message == "/kick" then -- The old if statement from earlier
game.ReplicatedStorage.KickQuestion1:FireAllClients()
end
What we are doing here is fairly simple. We are firing that Remote Event, KickQuestion1
to ALL of the clients. This will show up in all of the clients’ chats. So, we of course need to make that event do something, so let’s add the following code to our ChatSender
script.
game.ReplicatedStorage.KickQuestion1.OnClientEvent:Connect(function()
local StarterGui = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
StarterGui:SetCore("ChatMakeSystemMessage", {
Text = "Who would you like to kick?";
Color = Color3.fromRGB(255, 255, 255); --Chat message color, defaults to white
Font = Enum.Font.SourceSansBold; --Chat message font, defaults to SourceSansBold
TextSize = 18 --Text size, defaults to 18
})
end)
until Success
end)
What this code is doing, is using a function called SetCore
. That is a function that can set CoreGUIs, such as the Chat in this case, or things like the TopBar. This script is PCalling a function, for more info on pcalls, you can click on this awesome tutorial by @ReturnedTrue. We are pcalling a function that sets a core GUI, in this case a chat message. We are doing it with a table with the info needed for the message. There is Text
, Color
, Font
, and TextSize
. All needed for a chat message. Now, let’s get back to our ChatHandler
script!
if message == "/kick" then -- The old if statement from earlier
game.ReplicatedStorage.KickQuestion1:FireAllClients()
player.Chatted:Connect(function(message)
local kickedplayer = game.Players:FindFirstChild(message)
game.ReplicatedStorage.KickQuestion2:FireAllClients()
end
end
Here, we are having the player chat again, and then connecting it to the parameter message. We are then finding the first child of the Players
service, who will be kicked. Now, we have one more remote event to handle.
game.ReplicatedStorage.KickQuestion2.OnClientEvent:Connect(function()
local StarterGui = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
StarterGui:SetCore("ChatMakeSystemMessage", {
Text = "What were they doing?";
Color = Color3.fromRGB(255, 255, 255); --Chat message color, defaults to white
Font = Enum.Font.SourceSansBold; --Chat message font, defaults to SourceSansBold
TextSize = 18 --Text size, defaults to 18
})
end)
until Success
end)
This script is pretty much the same, except for two key elements. We are instead handling the event KickQuestion2
instead of KickQuestion1
, and are using a different text, What were they doing?
This is going to come in handy, as when you kick a player, you can use a reason within the parentheses. For example,
player:Kick("STOP IT!")
It would then show that they were disconnected from the game, with the text, STOP IT!
Now, let’s get back to the commands.
if message == "/kick" then -- The old if statement from earlier
game.ReplicatedStorage.KickQuestion1:FireAllClients()
player.Chatted:Connect(function(message)
local kickedplayer = game.Players:FindFirstChild(message)
game.ReplicatedStorage.KickQuestion2:FireAllClients()
player.Chatted:Connect(function(message)
kickedplayer:Kick(message)
game.ReplicatedStorage.KickSuccess:FireAllClients()
end)
end
end
You’ll notice here, we have the player chat Again Yes, you read that right, again. We need to get the message again, then we need to actually Kick()
the player. Notice, within the parentheses, we have message
. This means that whatever the player messaged last, that will be what they are kicked for. Now, we have one more event to handle. It’s called KickSuccess
. I’m going to challenge you to write the code for this one. We want it to send the message, Successfully kicked player!
Solution
game.ReplicatedStorage.KickSuccess.OnClientEvent:Connect(function()
local StarterGui = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
StarterGui:SetCore("ChatMakeSystemMessage", {
Text = "Successfully Kicked player!";
Color = Color3.fromRGB(255, 255, 255); --Chat message color, defaults to white
Font = Enum.Font.SourceSansBold; --Chat message font, defaults to SourceSansBold
TextSize = 18 --Text size, defaults to 18
})
end)
until Success
end)
Now that we have that working, let’s move onto the next command!
/Kill
This is another command commonly used with admin systems, and it kills whoever you’d like! Let’s start by firing the KillQuestion
Remote Event.
if message == "/kill" then
game.ReplicatedStorage.KillQuestion:FireAllClients()
end
Now of course, we need to handle said event, so going back to the ChatSender
script:
game.ReplicatedStorage.KillQuestion.OnClientEvent:Connect(function()
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "Who would you like to kill?";
Color = Color3.fromRGB(255, 0, 0);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end)
You’ll notice a few things here, the text is different, being “Who would you like to kill?”. The color is also different, it’s red this time. I’m going to use a different color for each command. Now, we need further code in the ChatHandler
.
if message == "/kill" then
game.ReplicatedStorage.KillQuestion:FireAllClients()
player.Chatted:Connect(function(message)
local killPlayer = game.Players:FindFirstChild(message)
local killCharacter = killPlayer.Character
local human = killCharacter:FindFirstChild("Humanoid")
human.Health = 0
game.ReplicatedStorage.KillSuccess:FireAllClients()
end)
end
Let’s walk through this code. We are getting the player to chat again, and getting the message. The next few lines are getting the player that will be killed. The killplayer
is the actual player in game.Players
. It’s killCharacter
is the model of the player in the workspace, and the human is the Humanoid
within that. We then set the health to 0. You’ll notice we are firing another remote event, so we of course need to handle that.
game.ReplicatedStorage.KillSuccess.OnClientEvent:Connect(function()
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "Successfully killed player!";
Color = Color3.fromRGB(255, 0, 0);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end)
We are really just sending a success message in the chat. Everything but the Text
is the same. Now we need to make the /speed
command! Let’s add some code into another if statement
.
if message == /speed then
game.ReplicatedStorage.SpeedQuestion:FireAllClients()
end
This code is pretty self explanatory. We are just firing a remote event. Let’s now make that event do something.
game.ReplicatedStorage.SpeedQuestion.OnClientEvent:Connect(function()
local StarterGui = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
StarterGui:SetCore("ChatMakeSystemMessage", {
Text = "What walkspeed do you want?";
Color = Color3.fromRGB(0, 255, 255); --Chat message color, defaults to white
Font = Enum.Font.SourceSansBold; --Chat message font, defaults to SourceSansBold
TextSize = 18 --Text size, defaults to 18
})
end)
until Success
end)
This code is fairly similar to the other ones, we just have a few different things. We are of course handling a different event, and changing the text. The text color is also different, it’s blue this time. After we send this question, we need to have the player chat again.
if message == "/speed" then
game.ReplicatedStorage.SpeedQuestion:FireAllClients()
player.Chatted:Connect(function(message)
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
humanoid.WalkSpeed = message
game.ReplicatedStorage.SpeedSuccess:FireAllClients(message)
end)
end
The new code here is again having the player chat, then finding their character through player.Character
. Then we need to find the Humanoid
of the character
, and change the walkspeed to message
. Notice we are firing the remote event with the parameter message
this time. That can be found by special handling. Look at this code:
game.ReplicatedStorage.SpeedSuccess.OnClientEvent:Connect(function(Event)
local StarterGui = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
StarterGui:SetCore("ChatMakeSystemMessage", {
Text = "Successfully changed walkspeed to "..Event;
Color = Color3.fromRGB(0, 255, 255); --Chat message color, defaults to white
Font = Enum.Font.SourceSansBold; --Chat message font, defaults to SourceSansBold
TextSize = 18 --Text size, defaults to 18
})
end)
until Success
end)
Notice how we are connecting the function with the parameter Event
. This is going to get the message
we fired it with. We use Event
in the text to show what the speed was changed to. After you type a string value, saying ..something
will add in a variable. The rest of the code is the same. Let’s move on to the teleport command!
/Teleport
We’ve reached the final command! It’s time to teleport people! We need to start by making sure we have the teleport events, again, shown here:
Now we need to start adding code! Let’s start in the ChatHandler
script.
if message == "/teleport" then
game.ReplicatedStorage.TeleportQuestion:FireAllClients()
end
All we are doing here is simply firing the remote event. We of course now have to handle it in ChatSender
.
game.ReplicatedStorage.TeleportQuestion.OnClientEvent:Connect(function()
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "Where would you like to go?";
Color = Color3.fromRGB(255, 0, 255);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end)
This script is pretty much the same, the ScreenGui
variable is different because I got lazy and didn’t want to type the whole thing. The color this time is pink, and the text is asking where the player wants to go. Now we need to go back to our original script.
if message == "/teleport" then
game.ReplicatedStorage.TeleportQuestion:FireAllClients()
player.Chatted:Connect(function(message)
local character = player.Character
local HRP = character:FindFirstChild("HumanoidRootPart")
HRP.CFrame = CFrame.new(Vector3.new(message))
game.ReplicatedStorage.TeleportSuccess:FireAllClients()
end)
So what we are doing here is having the player chat yet again, and then defining a few things. We are getting the player’s character, then finding the HumanoidRootPart
, or in this script, HRP
. The way to successfully change a player’s position is through their HumanoidRootPart
. We do have to change the CFrame
instead of Position
. We are changing the CFrame
with a Vector3
, which is the message
in this case. Finally, we fire a remote event. Handling is quite simple.
game.ReplicatedStorage.TeleportSuccess.OnClientEvent:Connect(function()
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "Successfully teleported!";
Color = Color3.fromRGB(255, 0, 255);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end)
We have the same code, with the Text
“Successfully teleported!”. Anyways, here’s the full code again for those of you following along.
ServerScript
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
if message == "/kick" then
game.ReplicatedStorage.KickQuestion1:FireAllClients()
player.Chatted:Connect(function(message)
local players = game:GetService("Players")
local kickedPlayer = players:FindFirstChild(message)
game.ReplicatedStorage.KickQuestion2:FireAllClients()
player.Chatted:Connect(function(message)
kickedPlayer:Kick(message)
game.ReplicatedStorage.KickSuccess:FireAllClients()
end)
end)
end
if message == "/speed" then
game.ReplicatedStorage.SpeedQuestion:FireAllClients()
player.Chatted:Connect(function(message)
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
humanoid.WalkSpeed = message
game.ReplicatedStorage.SpeedSuccess:FireAllClients(message)
end)
end
if message == "/kill" then
game.ReplicatedStorage.KillQuestion:FireAllClients()
player.Chatted:Connect(function(message)
local killPlayer = game.Players:FindFirstChild(message)
local killCharacter = killPlayer.Character
local human = killCharacter:FindFirstChild("Humanoid")
human.Health = 0
game.ReplicatedStorage.KillSuccess:FireAllClients()
end)
end
if message == "/teleport" then
game.ReplicatedStorage.TeleportQuestion:FireAllClients()
player.Chatted:Connect(function(message)
local character = player.Character
local HRP = character:FindFirstChild("HumanoidRootPart")
HRP.CFrame = CFrame.new(Vector3.new(message))
game.ReplicatedStorage.TeleportSuccess:FireAllClients()
end)
end
end)
end
end)
LocalScript in StarterPlayerScripts
game.ReplicatedStorage.KickQuestion1.OnClientEvent:Connect(function()
local StarterGui = game:GetService(“StarterGui”)
repeat
wait()
local Success = pcall(function()
StarterGui:SetCore(“ChatMakeSystemMessage”, {
Text = “Who would you like to kick?”;
Color = Color3.fromRGB(255, 255, 255); --Chat message color, defaults to white
Font = Enum.Font.SourceSansBold; --Chat message font, defaults to SourceSansBold
TextSize = 18 --Text size, defaults to 18
})
end)
until Success
end)
game.ReplicatedStorage.KickQuestion2.OnClientEvent:Connect(function()
local StarterGui = game:GetService(“StarterGui”)
repeat
wait()
local Success = pcall(function()
StarterGui:SetCore(“ChatMakeSystemMessage”, {
Text = “What were they doing?”;
Color = Color3.fromRGB(255, 255, 255); --Chat message color, defaults to white
Font = Enum.Font.SourceSansBold; --Chat message font, defaults to SourceSansBold
TextSize = 18 --Text size, defaults to 18
})
end)
until Success
end)
game.ReplicatedStorage.KickSuccess.OnClientEvent:Connect(function()
local StarterGui = game:GetService(“StarterGui”)
repeat
wait()
local Success = pcall(function()
StarterGui:SetCore(“ChatMakeSystemMessage”, {
Text = “Successfully Kicked!”;
Color = Color3.fromRGB(255, 255, 255); --Chat message color, defaults to white
Font = Enum.Font.SourceSansBold; --Chat message font, defaults to SourceSansBold
TextSize = 18 --Text size, defaults to 18
})
end)
until Success
end)
game.ReplicatedStorage.SpeedQuestion.OnClientEvent:Connect(function()
local StarterGui = game:GetService(“StarterGui”)
repeat
wait()
local Success = pcall(function()
StarterGui:SetCore(“ChatMakeSystemMessage”, {
Text = “What walkspeed do you want?”;
Color = Color3.fromRGB(0, 255, 255); --Chat message color, defaults to white
Font = Enum.Font.SourceSansBold; --Chat message font, defaults to SourceSansBold
TextSize = 18 --Text size, defaults to 18
})
end)
until Success
end)
game.ReplicatedStorage.SpeedSuccess.OnClientEvent:Connect(function(Event)
local StarterGui = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
StarterGui:SetCore("ChatMakeSystemMessage", {
Text = "Successfully changed walkspeed to "..Event;
Color = Color3.fromRGB(0, 255, 255); --Chat message color, defaults to white
Font = Enum.Font.SourceSansBold; --Chat message font, defaults to SourceSansBold
TextSize = 18 --Text size, defaults to 18
})
end)
until Success
end)
game.ReplicatedStorage.KillQuestion.OnClientEvent:Connect(function()
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "Who would you like to kill?";
Color = Color3.fromRGB(255, 0, 0);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end)
game.ReplicatedStorage.KillSuccess.OnClientEvent:Connect(function()
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "Successfully killed player!";
Color = Color3.fromRGB(255, 0, 0);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end)
game.ReplicatedStorage.TeleportQuestion.OnClientEvent:Connect(function()
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "Where would you like to go?";
Color = Color3.fromRGB(255, 0, 255);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end)
game.ReplicatedStorage.TeleportSuccess.OnClientEvent:Connect(function()
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "Successfully teleported!";
Color = Color3.fromRGB(255, 0, 255);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end)
Advanced
If you want to view the full code we’re making today, click below!
Code
ServerScript
game.Players.PlayerAdded:Connect(function(player)
local admins = {
"punishertheawesome";
"YourUserName";
"AnotherUserName"
}
if player.Name == admins[1] or admins[2] or admins[3] then
local messages = {
"/kick";
"/kill";
"/speed";
"/teleport"
}
player.Chatted:Connect(function(message)
if message == messages[1] then
game.ReplicatedStorage.ChatEvent:FireAllClients("KickQ1")
player.Chatted:Connect(function(message)
local kickedPlayer = game.Players:FindFirstChild(message)
game.ReplicatedStorage.ChatEvent:FireAllClients("KickQ2")
player.Chatted:Connect(function(message)
kickedPlayer:Kick(message)
game.ReplicatedStorage.ChatEvent:FireAllClients("KickSuccess")
end)
end)
end
if message == messages[3] then
game.ReplicatedStorage.ChatEvent:FireAllClients("SpeedQ")
player.Chatted:Connect(function(message)
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
humanoid.WalkSpeed = message
game.ReplicatedStorage.ChatEvent:FireAllClients("SpeedSuccess")
end)
end
if message == messages[2] then
game.ReplicatedStorage.ChatEvent:FireAllClients("KillQ")
player.Chatted:Connect(function(message)
local killedPlayer = game.Players:FindFirstChild(message)
local killCharacter = killedPlayer.Character
local humanoid = killCharacter:FindFirstChild("Humanoid")
humanoid.Health = 0
game.ReplicatedStorage.ChatEvent:FireAllClients("KillSuccess")
end)
end
if message == messages[4] then
game.ReplicatedStorage.ChatEvent:FireAllClients("TeleQ")
player.Chatted:Connect(function(message)
local character = player.Character
local HRP = character:FindFirstChild("HumanoidRootPart")
HRP.CFrame = CFrame.new(Vector3.new(message))
game.ReplicatedStorage.ChatEvent:FireAllClients("TeleSuccess")
end
end)
end
end)
LocalScript in StarterPlayerScripts
game.ReplicatedStorage.ChatEvent.OnClientEvent:Connect(function(Event)
local eventNames = {
"KickQ1";
"KickQ2";
"KickSuccess";
"SpeedQ";
"SpeedSuccess";
"KillQ";
"KillSuccess";
"TeleQ";
"TeleSuccess"
}
if Event == eventNames[1] then
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "Who would you like to kick?";
Color = Color3.fromRGB(255, 255, 255);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end
if Event == eventNames[2] then
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "What were they doing?";
Color = Color3.fromRGB(255, 255, 255);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end
if Event == eventNames[3] then
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "Successfully kicked player!";
Color = Color3.fromRGB(255, 255, 255);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end
if Event == eventNames[4] then
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "What walkspeed do you want?";
Color = Color3.fromRGB(255, 0, 255);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end
if Event == eventNames[5] then
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "Successfully changed walkspeed!";
Color = Color3.fromRGB(255, 0, 255);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end
if Event == eventNames[6] then
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "Who would you like to kill?";
Color = Color3.fromRGB(255, 0, 0);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end
if Event == eventNames[7] then
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "Successfully killed player!";
Color = Color3.fromRGB(255, 0, 0);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end
if Event == eventNames[8] then
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "Where would you like to go?";
Color = Color3.fromRGB(255, 255, 0);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end
if Event == eventNames[9] then
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "Successfully teleported!";
Color = Color3.fromRGB(255, 255, 0);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end
end
end)
Setup
The setup for this system is a lot simpler, as we only need one RemoteEvent
. I’m calling mine ChatEvent
. I am also going to explain this one a little less, as the simple version has a lot of explanation in it. I will only go in depth with the new stuff in this version. Let’s get started by getting the player, and making an admin table.
game.Players.PlayerAdded:Connect(function(player)
local admins = {
"punishertheawesome";
"Officiall_Studios";
"YourUserName";
}
end)
All we are doing here is getting the player with function(player)
, and adding a table of admin usernames. Let’s now check if the player is any one of these.
game.Players.PlayerAdded:Connect(function(player)
local admins = {
"punishertheawesome";
"Officiall_Studios";
"YourUserName";
}
if player.Name == admins[1] or admins[2] or admins[3] then
player.Chatted:Connect(function(message)
end)
end
end)
We are checking if the player is any number of the table, so admins[1]
would be “punishertheawesome”, and admins[2]
would be “Officiall_Studios”, and so on and so forth. We are then having the player chat, and getting the message
. Let’s now add a table with the message commands.
game.Players.PlayerAdded:Connect(function(player)
local admins = {
"punishertheawesome";
"Officiall_Studios";
"YourUserName"
}
if player.Name == admins[1] or admins[2] or admins[3] then
player.Chatted:Connect(function(message)
local messages = {
"/kick";
"/kill";
"/speed";
"/teleport"
}
if message == messages[1] then
end
if message == messages[2] then
end
if message == messages[3] then
end
if message == messages[4] then
end
end)
end
end)
So here we have a table with the messages, then 4 if statements
to check what the message is with each string in the table. Now it’s time to start filling in functions! Let’s start with /kill
.
if message == messages[1] then
game.ReplicatedStorage.ChatEvent:FireAllClients("KickQ1")
player.Chatted:Connect(function(message)
local kickedPlayer = game.Players:FindFirstChild(message)
game.ReplicatedStorage.ChatEvent:FireAllClients("KickQ2")
player.Chatted:Connect(function(message)
kickedPlayer:Kick(message)
game.ReplicatedStorage.ChatEvent:FireAllClients("KickSuccess")
end)
end)
Let’s briefly go over this code. First off we are firing our ChatEvent
, with the parameter KickQ1
. This can be handled in the LocalScript
, which we will cover in a minute. All this does is make a chat message asking who needs to be kicked. Then we have the player chat again, and define the player being kicked by finding who the message is. We are searching in Players
. After that, we are firing the event with “KickQ2”. We are going to get these parameters in the ChatSender
script.
game.ReplicatedStorage.ChatEvent.OnClientEvent:Connect(function(Event)
local eventNames = {
"KickQ1";
"KickQ2";
"KickSuccess";
"SpeedQ";
"SpeedSuccess";
"KillQ";
"KillSuccess";
"TeleQ";
"TeleSuccess"
}
if Event == eventNames[1] then
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "Who would you like to kick?";
Color = Color3.fromRGB(255, 255, 255);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end
if Event == eventNames[2] then
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "What were they doing?";
Color = Color3.fromRGB(255, 255, 255);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end
Okay, I know this is a lot of code, but let’s break it down a little bit. We need to first of all connect the remote event to a function, then we need to get Event
, which is the text we fire it with. Our table is all of the things we will eventually fire it with, then we check if it is a number of that table. We then are setting a CoreGui
, which are things like the topbar, or the chat in this case. We are setting it with a table of all the things needed, such as the text and the font and the color. We do this twice for the two remote events we fired. Let’s go back to the original script for a second. We are kicking the player with the message
, which basically just tells the player what the reason for being kicked was. Now for the next function.
if message == messages[2] then
game.ReplicatedStorage.ChatEvent:FireAllClients("KillQ")
player.Chatted:Connect(function(message)
local killedPlayer = game.Players:FindFirstChild(message)
local killCharacter = killedPlayer.Character
local humanoid = killCharacter:FindFirstChild("Humanoid")
humanoid.Health = 0
game.ReplicatedStorage.ChatEvent:FireAllClients("KillSuccess")
end)
end
This code is checking if the message is the 2nd item of the table, which is /kill
. We fire the event with the parameter KillQ
, and then find the Humanoid
that will be killed with a long string of :FindFirstChild
. We change Humanoid
's health to 0, then fire the event with KillSuccess
. Let’s now handle the event the two times we fired it.
if Event == eventNames[3] then
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "Successfully kicked player!";
Color = Color3.fromRGB(255, 255, 255);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end
if Event == eventNames[4] then
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "What walkspeed do you want?";
Color = Color3.fromRGB(255, 0, 255);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end
Here we are doing everything the same as last time, except for a few things. We are getting different strings of the table, eventNames[5]
and eventNames[6]
. (The table is out of order) We end up changing the text to ask who needs to be killed, and to print a success. The color is also different now, but it doesn’t have to be. Now we can do the next function!
if message == messages[3] then
game.ReplicatedStorage.ChatEvent:FireAllClients("SpeedQ")
player.Chatted:Connect(function(message)
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
humanoid.WalkSpeed = message
game.ReplicatedStorage.ChatEvent:FireAllClients("SpeedSuccess")
end)
end
This code is similar to our last one, we are checking if the message is a number in the statement, in this case [3]
which makes /speed
. We are then firing a remote event with SpeedQ
, which we will handle later. After this we get the player’s next Chatted
event. Next we find the Character
of the player, then the Humanoid
, then change it’s ``WalkSpeedto the
message. We are firing the remote event again with
SpeedSuccess`. Let’s now handle these two events.
if Event == eventNames[4] then
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "What walkspeed do you want?";
Color = Color3.fromRGB(255, 0, 255);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end
if Event == eventNames[5] then
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "Successfully changed walkspeed!";
Color = Color3.fromRGB(255, 0, 255);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end
These are also the exact same. The only difference is we are handling different parameters, sending different Text
, and using a different Color
. Now we can move onto the final command!
if message == messages[4] then
game.ReplicatedStorage.ChatEvent:FireAllClients("TeleQ")
player.Chatted:Connect(function(message)
local character = player.Character
local HRP = character:FindFirstChild("HumanoidRootPart")
HRP.CFrame = CFrame.new(Vector3.new(message))
game.ReplicatedStorage.ChatEvent:FireAllClients("TeleSuccess")
end
end)
end
end)
This code is slightly different than the other code. We are still checking the message
, and getting the player’s Character
, but that’s where it ends. We start by firing the remote event with TeleQ
, then we need the player to chat again. We get the Character
, then find a new part. We are finding the HumanoidRootPart
of the player. This is what we move to teleport a player. After that we change the CFrame
of the HumanoidRootPart
, because that’s the way of safely teleporting a Humanoid
. Changing Position
will kill them. The CFrame
is a Vector3
, which is made of message
, allowing you to choose where you go. Now we just have to handle the two events we fired!
if Event == eventNames[8] then
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "Where would you like to go?";
Color = Color3.fromRGB(255, 255, 0);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end
if Event == eventNames[9] then
local SG = game:GetService("StarterGui")
repeat
wait()
local Success = pcall(function()
SG:SetCore("ChatMakeSystemMessage", {
Text = "Successfully teleported!";
Color = Color3.fromRGB(255, 255, 0);
Font = Enum.Font.SourceSansBold;
TextSize = 18
})
end)
until Success
end
end
end)
You know the drill. All we are doing here is sending two chat messages, with the last items of the table. The color and text are different, but nothing else is. Anyways, congratulations! You’ve made a chat system!
Outro
Well, that’s it for today! Thank you for reading! I hope you not only learned how to make chat commands, but about remote events and how to use them! If you want to view the video version, click here! If you want to see them all, click here! If you have any questions, feel free to reply! Thanks for reading! Have a good day!