What I’m Trying to Achieve
I’m attempting to make an admin system and it’s going quite well; however… I’m unable to send the entire string to my message command with a Username inside of it
Issue I’m Having
The issue is that when I use the message command; :m
, if the first word has a string of a username; it goes through my FindPlayers function and it instead sends the username through the argument and doesn’t send the rest of the string that’s needed.
Solutions I’ve Tried
The only solution I’ve been able to think of is; I make one to three more functions and have the commands go through a function check for each command but I find that repetitive and I believe their may be another way to work around this.
Script Command
--//Made By MillerrIAm\\--
--/Services\--
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local TeleportService = game:GetService("TeleportService")
local TweenService = game:GetService("TweenService")
local RandomService = Random.new()
--/Variables\--
local ToolsFolder = ServerStorage:FindFirstChild("Tools") or ServerStorage
local playerCheck = require(script.Parent)
local Prefix = ":"
local SystemTitle = "System Message" -- What you want the system message to be called.
--/Commands\--
-- I have a list of commands that are already programmed in and work perfectly.
local Commands = {
["print"] = function(plr,arg)
print(arg)
end
;
--[Message Command]
["m"] = function(plr,msg)
print(msg)
if playerCheck.AdminCommands(plr) then
for _,Player in pairs (game.Players:GetPlayers()) do
if not Player.PlayerGui:FindFirstChild("MessageGUI") then
local GUI = script.MessageGUI:Clone()
GUI.Frame.MessageText.Text = msg
GUI.Parent = Player.PlayerGui
else
Player.PlayerGui["MessageGUI"]:Destroy()
local GUI = script.MessageGUI:Clone()
GUI.Frame.MessageText.Text = msg
GUI.Parent = Player.PlayerGui
end
end
end
end
}
--/Functions\--
function FindPlayers(plr,lowerplayer)
local arg = string.lower(lowerplayer)
local found = {}
if arg == "others" then
for _,player in pairs(Players:GetChildren()) do
if player.Name ~= plr.Name then
local name = string.lower(player.Name)
table.insert(found,player.Name)
end
end
elseif arg == "all" then
for _,Player in pairs (Players:GetChildren()) do
table.insert(found,Player.Name)
end
elseif arg == "me" then
table.insert(found,plr.Name)
elseif arg == "nonadmins" then
print(arg)
for _,Player in pairs (Players:GetChildren()) do
if not playerCheck.AdminCommands(Player) then
table.insert(found,Player.Name)
end
end
elseif arg == "admins" then
print(arg)
for _,Player in pairs (Players:GetChildren()) do
if playerCheck.AdminCommands(Player) then
table.insert(found,Player.Name)
end
end
elseif arg == "random" then
local rng = Random.new()
local players = Players:GetPlayers()
local greenIndex = players[rng:NextInteger(1, #players)]
for _, player in ipairs(players) do
if player == greenIndex then
table.insert(found,player.Name)
end
end
else
for _,Player in pairs(game.Players:GetChildren()) do
local name = string.lower(Player.Name)
if string.sub(name,1,#arg) == arg then
table.insert(found,Player.Name)
else
return false
end
end
end
return found
end
function Chatted(plr,msg)
local message = string.split(msg,"/e ")[2] or msg
if string.sub(message,1,#Prefix) == Prefix then
local split = string.split(message," ")
local command,args = split[1],split[2]
command = string.sub(string.lower(command),#Prefix+1)
if args ~= nil then
args = string.split(args,",")
else
args = " "
end
local extra_String = split[3] or plr
if Commands[command] then
if args ~= " " then
for _,arg in pairs(args) do
if FindPlayers(plr,arg) then
local playerTbl = FindPlayers(plr,arg)
for _,player in pairs(playerTbl) do
Commands[command](plr,player,extra_String)
end
else
local eCommand = string.split(msg,"/e ")[2] or msg
local commandSplit = string.split(eCommand,(command).." ")[2]
Commands[command](plr,commandSplit,extra_String)
end
end
else
Commands[command](plr)
end
end
end
end
--/Main Script\--
Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if playerCheck.AdminCommands(plr) or playerCheck.TemporaryAdmin(plr) then
Chatted(plr,msg)
end
end)
end)
Thank you to anyone who can help me.