Hello. Thank you for reading this. This is my first community tutorial, so please leave your feedback below. Anyways, my goal here is to help people achieve making their own chat commands. It’s fairly simple once you understand the most parts. I assume you have a basic understanding of scripting in Roblox, so with that, let’s set out variables.
Variables
local Admins = {""}
local Prefix = "/"
Now that we got that out of the way, we need to detect when a player joins, and if they are an admin, detect when they chat.
Code
game.Players.PlayerAdded:Connect(function(plr)
for _,v in pairs(Admins) do
if plr.Name == v then
plr.Chatted:Connect(function(msg)
end)
end
end
end)
Now with that set, we can finally start making commands! But, what if we don’t want the commands to be case-sensitive? Well, that’s easy. The following code will make your command not case-sensitive.
local loweredString = string.lower(msg)
local args = string.split(loweredString," ")
Now we can ACTUALLY start making commands. In this tutorial, I’ll show you how to make a WalkSpeed command.
Setting up WalkSpeed command
if args[1] == Prefix.."walkspeed" then
end
Now we need to set the player’s WalkSpeed to the second argument. But like we did with the message, we want to make the player’s name not case-sensitive. So add this to your script.
for _,player in pairs(game:GetService("Players"):GetPlayers()) do
if string.sub(string.lower(player.Name), 1, string.len(args[2])) ==string.lower(args[2]) then
end
end
Now we need to finish up, by setting the WalkSpeed.
Finishing up
player.Character.Humanoid.WalkSpeed = args[3]
Your code should now look line this:
local Admins = {""}
local Prefix = "/"
game.Players.PlayerAdded:Connect(function(plr)
for _,v in pairs(Admins) do
if plr.Name == v then
plr.Chatted:Connect(function(msg)
local loweredString = string.lower(msg)
local args = string.split(loweredString," ")
if args[1] == Prefix.."walkspeed" then
for _,player in pairs(game:GetService("Players"):GetPlayers()) do
if string.sub(string.lower(player.Name), 1, string.len(args[2])) == string.lower(args[2]) then
player.Character.Humanoid.WalkSpeed = args[3]
end
end
end
end)
end
end
end)
Thank you for taking time out of your day to read this. Please don’t just copy the code, I made this to help people learn. Happy programming!