Problem with custom admin command

  1. What do you want to achieve? Keep it simple and clear!
    Trying to make a command that can add value to your leaderstats

The command isnt running.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Ive tried disabling the other commands, and placing them at the bottom.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

I have pretty good scripting knowledge, but i havent really understood Module scripts until now, so i started making admin commands (in an admin panel to be exact). before adding the statsadd command, everything has been working fine.

Main script (located in serverscriptservice)

--// Admins

local admins = {
	"P_PGamer",
	"Jack123jona",
	"Guldstjarnan"
}

--// Banned
local banned = {
	""
}

--// Important assets
local gui = script:WaitForChild("Panel")


--// Admin Checker
game.Players.PlayerAdded:Connect(function(plr)
	
	local isAdmin = table.find(admins, plr.Name) ~= nil
	
	local isBanned = table.find(banned, plr.Name) ~= nil
	local isAltAccount = plr.AccountAge <= 0
	
	--[[
	if isAltAccount then
		warn(plr.Name .. " could potentially be an alternative account!")
		plr:Kick("Sorry! Your account has been detected as a spam account, and will be prohibited until tomorrow!")
		return
	end
	]]
	
	if isBanned then
		warn(plr.Name .. " joined as a banned player!")
		plr:Kick("You have been banned from this experience, and will be prohibited until the developer has allowed access.")
		print(plr.Name .. " was successfully kicked from the game!")
		return
	end
	
	if isAdmin then
		print(plr.Name .. " is an admin!")
	local panel = gui:Clone()
	panel.Parent = plr.PlayerGui

	end
	--// print(plr.Name .. " has joined, and is not an admin.")
	
	--//Commands
	local cmds = require(script.Commands)
	local prefix = "!"


	plr.Chatted:Connect(function(msg)
		if isAdmin then
			msg = string.lower(msg)
			local split = string.split(msg, " ")
			local cmd = split[1]
			if cmd:sub(1,1) ~= prefix then return end
			 print(cmd .. " function was used")
			if cmds[cmd:sub(2,#cmd)] then
				cmds[cmd:sub(2, #cmd)] (plr, split)
			end
		end
	end)
	
end)

Module script: (located in the main script)

local cmds = {}

--// Fun

	--// Value
function cmds.statsAdd(plr,args)
	if not args[2] then return end
	if string.lower(args[2]) == "me" then
		if not tonumber(args[3]) then
			warn("Invalid value")
			return
			end
				if not table.find(string.lower(plr.leaderstats), string.lower(args[4])) then
					warn("Couldnt find value with name: " .. args[4])
					return
			end
		local value = table.find(plr.leaderstats, args[4])
			if not value then
				return
			end
			
			value.Value = args[3]
		end
	end
	
	--// Kill
	function cmds.kill(plr,args)
		if not args[2] then return end
		if args[2] == "me" then
			local char = plr.Character
			local hum = char:WaitForChild("Humanoid", 4)
			if not hum then
				return
			end
			hum.Health = 0
			print("You used the !kill command on yourself!")
			return
		end
		local plr = nil

		for _,v in pairs(game.Players:GetPlayers()) do
			--// OLD VERSION: if string.match(v.Name:lower(), args[2]) then
			if string.lower(v.Name) == string.lower(args[2]) then
				plr = v
				break
			end
		end
		if not plr then
			warn(args[2] .." does not exist.")
			return
		end
		local char = plr.Character
		if not char then return end
		local hum = char:WaitForChild("Humanoid", 4)
		if not hum then return end
		hum.Health = 0
		print(args[2].." was killed!")
		return
	end

	--// Kick
	function cmds.Kick(plr,args)
		if not args[2] then return end
		if args[2] == "me" then
			plr:Kick("You have been kicked by an administrator.")
			return
		end
		plr = nil
		for _,v in pairs(game.Players:GetPlayers()) do
			if string.match(v.Name:lower(), args[2]) then
				plr = v
				break
			end
		end
		if not plr then
			warn(args[2] .." does not exist.")
			return
		end
		plr:Kick("You have been kicked by an administrator.")
		print(args[2].." was kicked from the experience!")
		
		
		
end

return cmds