You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? I want to create an admin commands that work on individual players, as well as tags such as “me”, “others”, “admins”, “all”, etc.
-
What is the issue? I was able to figure out how to use “me”, but I’m not sure how to make multiple players be teleported to one, how to speed up multiple players, etc.
Here is my code:
local admins = {
"TheVeryBoredCat",
"FPMFP",
"Player1",
"Player2",
}
local prefix = "/"
--SERVICES AND LOCATIONS
local storage = game:GetService("ReplicatedStorage")
--COMMAND LIST
local commands = {}
--FUNCTIONS AND THE CODE ITSELF
local function isAdmin(plr) --OBJECT VERSION OF PLR
for _, v in pairs(admins) do
if v == plr.Name then
return true
end
end
return false
end
local function findPlr(name, sender)
local plrs = game.Players:GetPlayers()
for i, plr in pairs(plrs) do
if string.lower(plr.Name) == name then
return plr --STRING VERSION OF PLR
elseif name == "me" then
return sender
end
end
return nil
end
commands.tp = function(sender, args) --SENDER IS AN OBJECT | ARGS ARE TABLE OF STRINGS
print ("Teleport function fired by "..sender.Name)
for _, plrName in pairs(args) do
print(plrName)
end
local plrTpingName = args[1]
local plrTpingToName = args[2]
if plrTpingName and plrTpingToName then
local plrTping = findPlr(plrTpingName, sender)
local plrTpingTo = findPlr(plrTpingToName, sender)
if plrTpingName and plrTpingToName then
plrTping.Character.HumanoidRootPart.CFrame = plrTpingTo.Character.HumanoidRootPart.CFrame
print("Teleport Successful")
end
end
end
commands.speed = function(sender, args)
print ("Speed function fired by "..sender.Name)
local plrToSpeed = args[1]
local walkSpeed = args[2]
if plrToSpeed then
local plr = findPlr(plrToSpeed, sender)
if plr then
plr.Character.Humanoid.WalkSpeed = tonumber(walkSpeed)
print(plrToSpeed.." was given WalkSpeed ".. walkSpeed)
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function()
plr.Chatted:Connect(function(msg, recipient)
if isAdmin(plr) then
msg = string.lower(msg)
local splitString = msg:split(" ")
local arg1 = splitString[1]
local cmd = arg1:split(prefix)
local cmdName = cmd[2]
if commands[cmdName] then
local args = {}
for i = 2, #splitString, 1 do
table.insert(args, splitString[i])
end
commands[cmdName](plr, args)
end
end
end)
end)
end)
- What solutions have you tried so far? I have looked for solutions on the DevHub, here on the DevForum, and on other online resources, but I could not find a solution.