I had a topic similar to this, but for some reason no one wanted to help me so I decided to create a new one.
I making a script for Admin Commands in chat.
I followed AlvinBlox’s tutorial on Admin Commands. They worked fine, but I wanted to transfer the commands to the Chat Modules so I could use RegisterProcessCommandFunction.
But when I tried to modify the script, it no longer worked.
Here is the code which is in a Module Script that’s located in the Chat Modules Folder.
-- Paste this example into a ModuleScript within the ChatModules folder.
local functionIds = {
[1] = "getPizza",
[2] = "kickPlayer"
}
local commands = {
[1] = "/pizza",
[2] = "/kick"
}
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
--local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
--local Humanoid = Character:WaitForChild("Humanoid")
local ServerScriptService = game:GetService("ServerScriptService")
local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
local toolId = 22596452 -- Pepperoni pizza slice gear
local prefix = "/"
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
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
local function processPizzaCommand(speakerName, message, channelName)
if string.sub(message, 1, commands[1]:len()) == commands[1] then
local model = game:GetService("InsertService"):LoadAsset(toolId)
local tool = model:GetChildren()[1]
local speaker = ChatService:GetSpeaker(speakerName)
local player = speaker:GetPlayer()
tool.Parent = player.Backpack
return true
end
return false
end
local function processKickCommand(sender, arguments, channelName)
if string.sub(arguments, 1, commands[2]:len()) == commands[2] then
for i, playerName in pairs(arguments) do
print(playerName)
end
local playerToKick = arguments[1]
if playerToKick then
local plrToKick = findPlayer(playerToKick.Name)
if plrToKick then
plrToKick:Kick()
print("Successfully Kicked")
return true
end
end
end
return false
end
Players.PlayerAdded:Connect(OnPlayerAdded)
local function runChatModule(ChatService)
ChatService:RegisterProcessCommandsFunction(functionIds[1], processPizzaCommand)
ChatService:RegisterProcessCommandsFunction(functionIds[2], processKickCommand)
end
-- Listen for players being added
return runChatModule
I’m getting this error when I try to run the Kick Command:
Can someone tell me what I’m doing wrong and help me?
(The Pizza Command Works but the Kick Command Doesn’t)
the problem here is you are trying to get the index and the string of the arguments
-- Paste this example into a ModuleScript within the ChatModules folder.
local functionIds = {
[1] = "getPizza",
[2] = "kickPlayer"
}
local commands = {
[1] = "/pizza",
[2] = "/kick"
}
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
--local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
--local Humanoid = Character:WaitForChild("Humanoid")
local ServerScriptService = game:GetService("ServerScriptService")
local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
local toolId = 22596452 -- Pepperoni pizza slice gear
local prefix = "/"
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
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
local function processPizzaCommand(speakerName, message, channelName)
if string.sub(message, 1, commands[1]:len()) == commands[1] then
local model = game:GetService("InsertService"):LoadAsset(toolId)
local tool = model:GetChildren()[1]
local speaker = ChatService:GetSpeaker(speakerName)
local player = speaker:GetPlayer()
tool.Parent = player.Backpack
return true
end
return false
end
local function processKickCommand(sender, arguments, channelName)
if string.sub(arguments, 1, commands[2]:len()) == commands[2] then
for i, v in pairs(arguments) do
print(v)
end
local playerToKick = arguments[1]
if playerToKick then
local plrToKick = findPlayer(playerToKick.Name)
if plrToKick then
plrToKick:Kick()
print("Successfully Kicked")
return true
end
end
end
return false
end
Players.PlayerAdded:Connect(OnPlayerAdded)
local function runChatModule(ChatService)
ChatService:RegisterProcessCommandsFunction(functionIds[1], processPizzaCommand)
ChatService:RegisterProcessCommandsFunction(functionIds[2], processKickCommand)
end
-- Listen for players being added
return runChatModule```
-- Paste this example into a ModuleScript within the ChatModules folder.
local functionIds = {
[1] = "getPizza",
[2] = "kickPlayer"
}
local commands = {
[1] = "/pizza",
[2] = "/kick"
}
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
--local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
--local Humanoid = Character:WaitForChild("Humanoid")
local ServerScriptService = game:GetService("ServerScriptService")
local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
local toolId = 22596452 -- Pepperoni pizza slice gear
local prefix = "/"
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
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
local function processPizzaCommand(speakerName, message, channelName)
if string.sub(message, 1, commands[1]:len()) == commands[1] then
local model = game:GetService("InsertService"):LoadAsset(toolId)
local tool = model:GetChildren()[1]
local speaker = ChatService:GetSpeaker(speakerName)
local player = speaker:GetPlayer()
tool.Parent = player.Backpack
return true
end
return false
end
local function processKickCommand(sender, arguments, channelName)
if string.sub(arguments, 1, commands[2]:len()) == commands[2] then
local playerToKick = arguments[1]
if playerToKick then
local plrToKick = findPlayer(playerToKick.Name)
if plrToKick then
plrToKick:Kick()
print("Successfully Kicked")
return true
end
end
end
return false
end
Players.PlayerAdded:Connect(OnPlayerAdded)
local function runChatModule(ChatService)
ChatService:RegisterProcessCommandsFunction(functionIds[1], processPizzaCommand)
ChatService:RegisterProcessCommandsFunction(functionIds[2], processKickCommand)
end
-- Listen for players being added
return runChatModule
-- Paste this example into a ModuleScript within the ChatModules folder.
local functionIds = {
[1] = "getPizza",
[2] = "kickPlayer"
}
local commands = {
[1] = "/pizza",
[2] = "/kick"
}
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
--local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
--local Humanoid = Character:WaitForChild("Humanoid")
local ServerScriptService = game:GetService("ServerScriptService")
local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
local toolId = 22596452 -- Pepperoni pizza slice gear
local prefix = "/"
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
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
local function processPizzaCommand(speakerName, message, channelName)
if string.sub(message, 1, commands[1]:len()) == commands[1] then
local model = game:GetService("InsertService"):LoadAsset(toolId)
local tool = model:GetChildren()[1]
local speaker = ChatService:GetSpeaker(speakerName)
local player = speaker:GetPlayer()
tool.Parent = player.Backpack
return true
end
return false
end
local function processKickCommand(sender, arguments, channelName)
if string.sub(arguments, 1, commands[2]:len()) == commands[2] then
local SplitMessage = arguments:split(" ")
local playerToKick = SplitMessage[2]
if playerToKick then
local plrToKick = game.Players:FindFirstChild(playerToKick)
if plrToKick then
plrToKick:Kick()
print("Successfully Kicked")
return true
end
end
end
return false
end
Players.PlayerAdded:Connect(OnPlayerAdded)
local function runChatModule(ChatService)
ChatService:RegisterProcessCommandsFunction(functionIds[1], processPizzaCommand)
ChatService:RegisterProcessCommandsFunction(functionIds[2], processKickCommand)
end
-- Listen for players being added
return runChatModule
-- Paste this example into a ModuleScript within the ChatModules folder.
local functionIds = {
[1] = "getPizza",
[2] = "kickPlayer"
}
local commands = {
[1] = "/pizza",
[2] = "/kick"
}
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
--local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
--local Humanoid = Character:WaitForChild("Humanoid")
local ServerScriptService = game:GetService("ServerScriptService")
local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
local toolId = 22596452 -- Pepperoni pizza slice gear
local prefix = "/"
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
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
local function processPizzaCommand(speakerName, message, channelName)
if string.sub(message, 1, commands[1]:len()) == commands[1] then
local model = game:GetService("InsertService"):LoadAsset(toolId)
local tool = model:GetChildren()[1]
local speaker = ChatService:GetSpeaker(speakerName)
local player = speaker:GetPlayer()
tool.Parent = player.Backpack
return true
end
return false
end
local function processKickCommand(sender, arguments, channelName)
if string.sub(arguments, 1, commands[2]:len()) == commands[2] then
local SplitMessage = arguments:split(" ")
local playerToKick = SplitMessage[2]
local Reason = SplitMessage[3]
if playerToKick then
local plrToKick = game.Players:FindFirstChild(playerToKick)
if plrToKick then
plrToKick:Kick(Reason)
print("Successfully Kicked")
return true
end
end
end
return false
end
Players.PlayerAdded:Connect(OnPlayerAdded)
local function runChatModule(ChatService)
ChatService:RegisterProcessCommandsFunction(functionIds[1], processPizzaCommand)
ChatService:RegisterProcessCommandsFunction(functionIds[2], processKickCommand)
end
-- Listen for players being added
return runChatModule