I’m following AlvinBlox’s tutorial on making Custom Admin commands. I’m trying to use RegisterProcessCommandsFunction so the commands will delete when executed but for some reason its returning an error.
Here is the code which is in a ModuleScript in the ChatModules Folder:
local commands = {}
local Players = game:GetService("Players")
local prefix = "/"
local function findPlayer(name)
for i, player in pairs(Players:GetPlayers()) do
if string.lower(player.Name) == name then
return player
end
end
return nil
end
commands.tp = function(speaker, arguments)
print("Function fired by " ..speaker.Name)
for i, playerName in pairs(arguments) do
print(playerName)
end
local playerToTeleportName = arguments[1]
local playerToTeleportToName = arguments[2]
if playerToTeleportName and playerToTeleportToName then
local plrToTeleport = findPlayer(playerToTeleportName)
local plrToTeleportTo = findPlayer(playerToTeleportToName)
if plrToTeleport and plrToTeleportTo then
plrToTeleport.Character.HumanoidRootPart.CFrame = plrToTeleportTo.Character.HumanoidRootPart.CFrame
print("Successfully Moved!")
end
end
end
local function OnPlayerAdded(player)
player.Chatted:Connect(function(message, recipient)
message = string.lower(message)
local splitString = message:split(" ")
local slashCommand = splitString[1]
local cmd = slashCommand:split(prefix)
local cmdName = cmd[2]
if commands[cmdName] then
local arguments = {}
for i = 2, #splitString, 1 do
table.insert(arguments, splitString[i])
end
commands[cmdName](player, arguments)
end
end)
end
Players.PlayerAdded:Connect(OnPlayerAdded)
local function Run(ChatService)
ChatService:RegisterProcessCommandsFunction(commands)
end
return Run
local module = {}
function module.set(arg)
print(arg)
end -- It'll be exported with any command that is made like this or:
module.set = function(arg)
print(arg)
end -- module exported commands
return module -- exporting the whole module table.
Local functions that aren’t exported nor accessible unless thru the command itself or stored in the module and is used by the module itself.
local commands = {}
local Players = game:GetService("Players")
local prefix = "/"
local function findPlayer(name)
for i, player in pairs(Players:GetPlayers()) do
if string.lower(player.Name) == name then
return player
end
end
return nil
end
function commands.tp(player, speaker, arguments)
player.Chatted:Connect(function(message, recipient)
message = string.lower(message)
local splitString = message:split(" ")
local slashCommand = splitString[1]
local cmd = slashCommand:split(prefix)
local cmdName = cmd[2]
if commands[cmdName] then
local arguments = {}
for i = 2, #splitString, 1 do
table.insert(arguments, splitString[i])
end
commands[cmdName](player, arguments)
end
end)
end
commands.tp = function(speaker, arguments)
print("Function fired by " ..speaker.Name)
for i, playerName in pairs(arguments) do
print(playerName)
end
local playerToTeleportName = arguments[1]
local playerToTeleportToName = arguments[2]
if playerToTeleportName and playerToTeleportToName then
local plrToTeleport = findPlayer(playerToTeleportName)
local plrToTeleportTo = findPlayer(playerToTeleportToName)
if plrToTeleport and plrToTeleportTo then
plrToTeleport.Character.HumanoidRootPart.CFrame = plrToTeleportTo.Character.HumanoidRootPart.CFrame
print("Successfully Moved!")
end
end
end
local function Run(ChatService)
ChatService:RegisterProcessCommandsFunction(commands)
end
return commands