- What do you want to achieve? Keep it simple and clear!
I want to the module to know if there is a player arg and what position that would be (“!fly me” would be commandArgs[1] which would be “me”)
- What is the issue? Include screenshots / videos if possible!
Whenever I try to execute a command on a specific player, for example: !jail playername, it does not work. However, it works when I use it on myself or on all players at once using key words! (me, all, others.)
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have attempted many different things none of which worked. No I have not looked on the dev forum
----- | Services | -----
local Services = _G["Services"]
----- | Variables | -----
local file = _G["File"]
local field = {}; field.__index = field
local temporaryStorage = {}
local Commands = require(script["Command List"])
----- | Methods | -----
function field:SetPrefix(player)
local Prefix = Services.ReplicatedStorage.FunctionStorage.Prefix:Invoke(player)
player:SetAttribute(`Prefix`,Prefix)
return player:GetAttribute(`Prefix`)
end
function field:CheckCommand(command)
local CommandList = require(script["Command List"])
if CommandList[command:lower()] or table.find(CommandList,command:lower()) then
return CommandList[command:lower()]
end
for _,MyCommand in pairs(CommandList) do
if not MyCommand.Alias then
if MyCommand.Name:lower() == command:lower() then
return MyCommand
end
else
if MyCommand.Name:lower() == command:lower() or table.find(MyCommand.Alias,command:lower()) then
return MyCommand
end
end
end
return
end
function field:CheckPrefix(player,message:string)
local prefix = player:GetAttribute(`Prefix`) or field:SetPrefix(player)
task.wait()
if string.find(message,prefix) then
local command = message:gsub(prefix ,"")
--warn(message:split(" ")[1])
local Check = field:CheckCommand(command:split(" ")[1])
task.wait()
if Check then
return Check
else
return
end
end
end
function getPlayerByKeyword(keyword: string, sender: Player)
local Playerlist = {}
if keyword:lower():gsub(" ", "") == "me" and not table.find(Playerlist, sender) then
table.insert(Playerlist, sender)
end
if keyword:lower():gsub(" ", "") == "all" then
for _, player in game:GetService("Players"):GetPlayers() do
if table.find(Playerlist, player) then continue end
table.insert(Playerlist, player)
end
end
if keyword:lower():gsub(" ", "") == "others" then
for _, player in game:GetService("Players"):GetPlayers() do
if table.find(Playerlist, player) or player == sender then continue end
table.insert(Playerlist, player)
end
end
if keyword:lower():gsub(" ", "") == "me" then
table.insert(Playerlist, sender)
end
if keyword:lower():gsub(" ", "") ~= "me" and keyword:lower():gsub(" ", "") ~= "all" and keyword:lower():gsub(" ", "") ~= "others" then
for i, player in pairs(Services.Players:GetPlayers()) do
if string.lower(player.Name) == keyword or string.lower(player.Name):find(keyword) then
table.insert(Playerlist, player)
end
end
end
return Playerlist
end
function field:Chatted(sender, message)
local GetRank = Services[`RankService`]:GetRank(sender)
repeat task.wait() until GetRank ~= nil
if sender:GetAttribute(`Rank`) == `None` or GetRank == `None` then return end
local MyCommand = field:CheckPrefix(sender,message)
repeat task.wait() until MyCommand ~= nil
if MyCommand == nil then return end
if not table.find(MyCommand.Permissions,sender:GetAttribute(`Rank`)) then Services.ReplicatedStorage.EventStorage:FindFirstChild(`Notify`):FireClient(sender,{Title = `Notice`,Description = `Your rank is not high enough to use the "{MyCommand.Name}" command!`}) return end
local args = message:lower():split(" ")
local command = args[1]
local commandArgs = {}
if #args > 1 then
for i = 2, #args do
local arg = args[i]
local splitIndex = arg:find(" ")
if splitIndex then
local argName = arg:sub(1, splitIndex - 1)
local argValue = arg:sub(splitIndex + 1)
commandArgs[argName] = argValue
else
table.insert(commandArgs, arg)
end
end
end
if table.find(commandArgs,`me`) then
local players = getPlayerByKeyword(`me`,sender)
for _,player in pairs(players) do
local succ,err = pcall(function()
if MyCommand.Run then
commandArgs[1] = player
MyCommand.Run(sender,commandArgs)()
end
end)
end
elseif table.find(commandArgs,`all`) then
local players = getPlayerByKeyword(`all`,sender)
for _,player in pairs(players) do
local succ,err = pcall(function()
if MyCommand.Run then
commandArgs[1] = player
MyCommand.Run(player,commandArgs)()
end
end)
end
elseif table.find(commandArgs,`others`) then
local players = getPlayerByKeyword(`others`,sender)
for _,player in pairs(players) do
local succ,err = pcall(function()
if MyCommand.Run then
commandArgs[1] = player
MyCommand.Run(player,commandArgs)()
end
end)
if not succ then
warn(err)
end
end
else
local succ,err = pcall(function()
if MyCommand.Run then
MyCommand.Run(sender,commandArgs)()
end
end)
end
end
----- | Event Listeners | -----
for _,player in pairs(Services.Players:GetPlayers()) do
player.Chatted:Connect(function(message)
field:Chatted(player,message)
end)
end
Services.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
field:Chatted(player,message)
end)
end)
Services.ReplicatedStorage.EventStorage.ServerCommand.OnServerEvent:Connect(function(player,message)
field:Chatted(player,message)
end)
return field
Thanks for reading my post.