Problem with custom addmin command script

Im getting HUGE issues from my script

i followed a tutorial form alvin_blox on making admin commands and i got a huge problem

here is the script: vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

local Admins = {"plr1", "pl2"}
local Commands = {}
local prefix = "/"
function Commands.addstat(player, arg)
	print(player, #arg)
	
	local Players = game:GetService("Players")
	local stat = arg[1]
	local amt = arg[2]
	if player and stat and amt then
		Players[player].leaderstats[stat].Value = Players[player].leaderstats[stat].Value + amt
	end
end

function Commands.removestat(player, arg)
	local Players = game:GetService("Players")
	local stat = arg[1]
	local amt = arg[2]
	if player and stat and amt then
		Players[player].leaderstats[stat].Value = Players[player].leaderstats[stat].Value - amt
	end
end

function Commands.setstat(player, arg)
	local Players = game:GetService("Players")
	local stat = arg[1]
	local amt = arg[2]
	if player and stat and amt then
		Players[player].leaderstats[stat].Value = amt
	end
end

function Commands.tp(plr, arg)
	local Players = game:GetService("Players")
	local plr2 = arg[1]
	if plr and plr2 then
		local Char1 = workspace[plr]
		local Char2 = workspace[plr2]
		if Char1 and Char2 then
			Char1:MoveTo(Char2.HumanoidRootPart)
		end
	end
end

game.Players.PlayerAdded:Connect(function(plr)
	for _, Admins in pairs(Admins) do
			plr.Chatted:Connect(function(chat, rec)
			chat = string.lower(chat)
				-- tp will be the example command	
			local splitstring = chat:split(" ") -- {"/tp", "plr, "plr2"}
			
			print(#splitstring) -- 3
					
			local sCom = prefix..splitstring[1] -- "/tp"
			
			print(sCom) -- "/tp"
					
			local cmd = sCom.split(sCom, "") -- {"/", "tp"}
			
			print(#cmd)
			local cmdName = cmd[2]
			
			print(cmdName)
					
				if Commands[cmdName] then
						
				local args = {}
						
					for i = 2,#splitstring,1 do
						table.insert(args, splitstring[i])
				end
				
				print(args)
						
					Commands[cmdName](plr, args)
			end
		end)
	end
end)
2 Likes

what and where is the problem tho

1 Like

the problem is the

			local cmd = sCom.split(sCom) -- {"/", "tp"}
			
			print(#cmd)
			local cmdName = cmd[2]
			
			print(cmdName)

cmdName remains nil

and there are other problems i cant show

and when i do cmd[1] it just prints “/tp”

1 Like