So, I have been trying to create a new admin script for my game, but I am running into some problems. my goal is to take the message that was chatted, see if it matches with a command, and then return many values, one of them being a function that I can run, or the name of the function I can run. I need to be able to store these functions or the function names in a dictionary, and I need a demonstration of how I can call the function after it is returned, whether it is a function name or the actual function. I need to finally make sure that all values can be stored in one key. Is this possible, are there any alternatives, and if so, what do I need to change?

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
-- Command to choose a team (note the trailing space)
local joinCommand = "/jointeam "
local Commands = {[":teleport"] = function() print("oofff") end}
function findTeamByName(name)
	-- First, check for the exact name of a team
	if Teams:FindFirstChild(name) then return Teams[name] end
	-- Let's check for case-insensitive partial matches, like "red" for "Red Robins"
	for _, team in pairs(Teams:GetChildren()) do
		if team.Name:sub(1, name:len()):lower() == name:lower() then
			return team
		end
	end
	-- If we get to this point, no team matched the one we were looking for :(
end

function MatchToCommand(String)
	local FilteredString = String:lower()
	for k, v in pairs(Commands) do
		if k:find(FilteredString) and FilteredString:len() >= 4 then
			print("hmmm")
			return true, k
		end
	end
end

local function OnPlayerChatted(player, msg, recipient)
	print(msg)
	if --[[message:sub(1, joinCommand:len()):lower() == joinCommand:lower()]]MatchToCommand(msg) then
		--[[ Matched "/JOINTEAM xyz" to our join command prefix "/jointeam "
		local teamName = message:sub(joinCommand:len() + 1) -- Cut out the "xyz" from "/jointeam xyz"
		local team = findTeamByName(teamName)
		if team then
			-- Set the team!
			player.Team = team
			player.Neutral = false
		else
			-- Tell the player that team could not be found :(
			player.Team = nil
			player.Neutral = true
		end]]
		
	end
end
--[[function FilterChat(Length)
	local self:sub
end]]
function AddToQueue(player)
	player.Chatted:Connect(function (...)
		OnPlayerChatted(player, ...)
	end)
end

Players.PlayerAdded:Connect(AddToQueue)

1 comment

0

This is all in a script, and ignore the comments. At the top with the table, I tried assigning a function to a key, but I don;t really know if that worked or to go from here.