How to create certain amount of variable for set arguments (post has more info

I’m currently working on a custom admin system. Notifications, GUIs, ModuleScripts, the whole shazam. (for my own game)

I’ve made the commands already, but I’m setting up the execution. My execute function requires the set arguements, and I have no clue how to create a set amount of variables for the set amount of arguements. First, look at one of my simpler commands. (Just focus on execute and it’s variables)

Info.Commands.To = { 
	["command"] = ":to",
	["ranon"] = "server",
	["arguements"] = 2,
	["requirement"] = 1,
	["execute"] = function(player, PlayerToTeleport)
		local StopLoop = false
		local success, errormsg = pcall(function()
			for i,v in pairs(game.Players:GetPlayers()) do
				if StopLoop == false then
					if string.match(string.lower(v.Name), string.lower(PlayerToTeleport)) then
						StopLoop = true
						local PlayerToTeleport = v
						player.Character.HumanoidRootPart.CFrame = PlayerToTeleport.Character.CFrame * CFrame.new(0,0,-3, 0,math.rad(180), 0)
					end
				end
			end
		end)
		if success and StopLoop then
			return "Executed"
		elseif not StopLoop then
			return "PlayerNotFound"	
		elseif errormsg then
			return errormsg
		else
			return "Fail"
		end
	end
}

Move onto my execution. (I’ll show the script for client commands execution.)

RepStor.AdminEvents.ClientExecution.OnClientInvoke = function(executeFunction, args)
	local arg1, arg2, arg3, arg4, arg5, arg6, arg7 = table.unpack(args)
	local Result = executeFunction(game.Players.LocalPlayer, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
	return Result
end

What I’m doing right now requires me to grab as much as I can. But if I give the variables as a full table, I’ll have to revamp all my commands. (Which is doable atm). Any thoughts, or should I pain my way through revamping my commands.

1 Like

I’m not sure what’s the issue here but, couldn’t you simply send the arguments table unpacked, without referring to each element?

1 Like

Okay this may sound stupid, but sending a table of variables into a function sends the full table, not the variables itself, right?? And if I send the full table, it can’t interpret that, it needs the variables seperately.

Yes, it sends the table itself, but I assumed you knew the existence of table.unpack (based on your code).

I’m aware, but the problem is identifying the certain amount of variables. I just tried using:

> local tablE = {"yes", "no", "maybe", "so"} local function yes(tab) print(tab) end yes(table.unpack(tablE))   -  Studio
  22:53:19.310  yes

In the command bar, but the issue is, it only returns the first variable of the table, making it a bit hard.

Note: I know most of the API on strings, and tables.

int select ( string cmd, Tuple args )
Returns the total number of arguments that were passed after the cmd argument, which must be "#" to use select in this fashion.

  1. print(select("#", "A", "B", "C")) --> 3

Lua Globals | select (roblox.com)

I see the how that might be useful, just not how to incorporate it into the script to make it work. You don’t need to write up a whole script, just explain how I’d theoretically do it.

Sure, but I need more clarification on what you want to achieve here.

I don’t know what variables you are referring to, and what would the importance of knowing their amounts.

Your function only expects 1 argument, therefore any extra ones are discarded. The wrapper here is useless – just do print(table.unpack(tablE))

2 Likes