This tutorial will have the example of one way. In this tutorial i will show you how to make Admin Commands
1 Make a script in ServerScriptService.
2 Make a table with the Admins:
local Admins = {"baum2409", "Player1"}
3 Lets make the script check if the player chatted:
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(message)
for i,v in pairs(Admins) do -- Checks if Player is a Admin.
if plr.Name == v then
end
end
end)
end)
4 Lets split the message:
local SplitMessage = message:split(" ")
or
local SplitMessage = string.split(message, " ")
5 Lets make a example command:
if SplitMessage[1] == "/example" then
local toprint = SplitMessage[2]
print(toprint)
end
I hope you have a great day and i hope you like this tutorial!
Maybe not what you want but my kill commands(not the best but it works):
if SplitMessage[1] == "/kill" then
local Player = SplitMessage[2]
if not Player then plr.Character:FindFirstChild("Humanoid").Health = 0 return end
if Player == "me" or Player == "Me" or Player == "" then
local Character = plr.Character
Character:FindFirstChild("Humanoid").Health = 0
elseif Player == "all" or Player == "All" then
for _,Plr in pairs(game.Players:GetPlayers()) do
Plr.Character:FindFirstChild("Humanoid").Health = 0
end
else
if game.Players:FindFirstChild(Player) then
game.Players:FindFirstChild(Player).Character:FindFirstChild("Humanoid").Health = 0
end
end
end
This is a nice start for an admin system but nowhere near a proper one.
You don’t even include string:lower() incase a user accidently spells the command with too many uppercase letters nor do you include any abbreviations for your commands making them hard to use.
Any good admin system requires both of those and that’s just the basics. I recommend rewriting your community resource and making it much more in depth and advanced so that the users/developers reading actually understand what you’re trying to show them instead of people just copy-pasting your code and not knowing how to properly make commands.
‘Kick’ command I just made(will need variables from above as well as inside the scope):
local commandText = SplitMessage[1]:lower() --Getting a lowercase version of the command name
local prefix = '!' -- A prefix to start off the message
local command = commandText:gsub('%'..prefix, '') --Get the command without prefix
if command == 'kick' then --If the command is 'kill'
local Player = SplitMessage[2]:lower() --Get the username from the SplitMessage index and make it lowercase.
if Player == "me" Player == "" then --If the player mentioned is 'me' or nothing
local Character = plr.Character or plr.CharacterAdded:Wait() --Get the player. If not there, wait.
Plr.Character:Kick("You have been kicked from the game by an administrator.") --Kick the user
elseif Player == "all" or Player == "a" then --If the player mentioned is 'all' or 'a'
for _,Plr in pairs(game.Players:GetPlayers()) do --Loop through the players
Plr.Character:Kick("You have been kicked from the game by an administrator.") --Kick the user
end
else --If none of the conditionals above were ran
for _,Plr in pairs(game.Players:GetPlayers()) do --Loop through the players
if Plr.Name:lower() == Player then -- If the player's name lowercased is equal to the Player provided
Plr.Character:Kick("You have been kicked from the game by an administrator.") --Kick the user
end
end
end
end
P.S. The first three lines you can use to create your own commands system using the same command if statement I just used.