Admin Command Parameter Table returning empty

I have this Custom Admin Command System that I used for ChatService, and I’m trying to port it to TextChatService. However, I’ve been running into an issue that I’ve been trying to fix for quite some time now).

(Note: The port was being based off this tutorial

I have the commands stored in a large dictionary with the arguments stored each command defined in the dictionary, like this:

local MarketplaceService = game:GetService("MarketplaceService")
local ServerStorage = game:GetService("ServerStorage")
local TeleportService = game:GetService("TeleportService")


local Commands = { 
	["kill"] = { -- Command Name
		Alias = nil, -- Alias Of The Command.
		['Arguments'] = {
			[1] = 'Player'
		},
		Execute = function(speaker, players)

			for i, player in ipairs(players) do
				local character = player.Character or player.CharacterAdded:Wait()
				character:BreakJoints()
			end
		end,
	},
}

return Commands

And my parameters are set up and unpacked like this:

local CommandFolder = Instance.new("Folder")
CommandFolder.Name = "Commands"
CommandFolder.Parent = TextChatService

local prefix = "/"

local Commands = require(script.Commands)


for CommandName, Data in pairs(Commands) do
	local TextChatCommand: TextChatCommand = Instance.new("TextChatCommand")
	TextChatCommand.PrimaryAlias = tostring(prefix .. CommandName) -- Sets The Primary Alias
	
	print(Data.Arguments)

	TextChatCommand.Parent = CommandFolder
	
	if Data.Alias ~= nil and type(Data.Alias) == "string" then -- Checks If The Command Has A Alias.
		TextChatCommand.SecondaryAlias = tostring(`{prefix}{Data.Alias}`) -- Sets The SecondaryAlias.
	end


	TextChatCommand.Triggered:Connect(function(textSource : TextSource, message : string) -- Triggers Whenever The Command Is Ran.
		local speaker = Players:GetPlayerByUserId(textSource.UserId) -- Gets The Player Who Called The Command
		
		local args = Util:SplitMessage(message)
		
		
		
		local parameters = {}
		local proceed = true
		
		for argIndex, arg in ipairs(Data.Arguments) do
			print(argIndex)
			print(arg)
			if not proceed then break end
			local wordType = typeof(arg)
			
			print(wordType)
				
			if wordType == 'string' then
				if arg == 'Player' then
					local players = Util:GetPlayers(speaker, args[argIndex])
					
					print(players)

					if players then
						table.insert(parameters, players)
						print(parameters)
					else
						proceed = false
					end
				elseif arg == 'Number' then
					table.insert(parameters, tonumber(args[argIndex]) or 1)
				elseif arg == 'String' then
					local combinedArray = {}
					for i, arg in pairs(args) do
						if i > 2 then
							table.insert(combinedArray, arg)
						end
					end
					local newParameter = Util.CombineSplitMessage(combinedArray)
					table.insert(parameters, newParameter)			
					break
				end
			end
		end


		
		print(proceed)
		if proceed then
			print(parameters)
			print(speaker)
			print(table.unpack(parameters))
			Data/Execute(speaker, unpack(parameters))
		end
		
		
	end)
end

My "Util" script thats used in the script above:
local Utilities = {}
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local Teams = game:GetService("Teams")

function Utilities:SplitMessage(message)
	local arguments = {}

	for i, argument in ipairs(string.split(message, ' ')) do
		table.insert(arguments, string.lower(argument))
	end

	return arguments
end

function Utilities:CombineSplitMessage(array)
	return table.concat(array, " ")
end


function Utilities:GetPlayers(speaker, target, ...)
	if not target then return end
	target = string.lower(target)

	local players = {}

	if target == 'all' or target == 'everyone' then
		players = Players:GetPlayers()
	elseif target == 'others' then
		for _, player in pairs(Players:GetPlayers()) do
			if (player == speaker) then continue end
			table.insert(players, player)
		end
	elseif target == 'me' then
		table.insert(players, speaker)
	elseif target == "premium" or target == "prem" then
		for i, player in ipairs(Players:GetPlayers()) do
			if player.MembershipType == Enum.MembershipType.Premium then
				table.insert(players, player)
			end
		end
	elseif target == "nonpremium" or target == "nonprem" then
		for _, player in pairs(Players:GetPlayers()) do
			if player.MembershipType == Enum.MembershipType.None then
				table.insert(players, player)
			end
		end
	elseif target == "friends" then
		for _, player in pairs(Players:GetPlayers()) do
			if player:IsFriendsWith(speaker.UserId) then
				table.insert(players, player)
			end
		end
	elseif target == "nonfriends" then
		for _, player in pairs(Players:GetPlayers()) do
			if not player:IsFriendsWith(speaker.UserId) and speaker.UserId ~= player.UserId then
				table.insert(players, player)
			end
		end
	elseif target == "group" then
		local groupIds = {}
		for _, groupId in pairs(table.pack(...)) do
			groupId = tonumber(groupId)
			if groupId then
				table.insert(groupIds, groupId)
			end
		end
		for _, player in pairs(Players:GetPlayers()) do
			for _, groupId in pairs(groupIds) do
				if player:IsInGroup(groupId) then
					table.insert(players, player)
					break
				end
			end
		end
	elseif target == "percent" or target == "percentage" then
		local maxPercent = 50
		local interval = 100 / #players
		if maxPercent >= (100 - (interval * 0.1)) then
			return players
		end
		local selectedPercent = 0
		repeat
			local randomIndex = math.random(1, #players)
			local selectedPlayer = players[randomIndex]
			table.insert(players, selectedPlayer)
			table.remove(players, randomIndex)
		until #players == 0 or selectedPercent >= maxPercent
	else
		local suitableMatches = {}

		for i,player in ipairs(Players:GetPlayers()) do
			local playerName = string.lower(player.Name)

			if playerName == target then
				suitableMatches = {player}
				break
			elseif string.find(playerName, target, 1, true) then
				table.insert(suitableMatches, player)
			end
		end

		players = {suitableMatches[1]}
	end

	return players
end

return Utilities

And for some reason, no matter what I try, the commands won’t run.
(I specifically run: /kill <player> (i.e. /kill valiantwind) in the chat.

After a bit of debugging, I found out that the parameters table returns empty even though it should contain the player defined and I can’t figure out why it doesn’t.

Can someone help me find out what I’m doing wrong?

3 Likes