Problem with Admin Commands

Hello fellow dev people!! I have been racking my brain on how to fix this system I made off a tutorial (But I change it a bit)

  1. What do you want to achieve? I have used a tutorial, I am not sure what happened. (I did ask the maker of it for some help, and they aren’t sure on how to fix it)

  2. What is the issue? I have put the 3 scripts down the bottom.

  3. What solutions have you tried so far? I have tried to fix it, but some of the script I am struggling to understand parts of the system. I have asked the tutorial creator but he doesn’t know how to fix it either.

There is 1 error that shows up when you type a command.

ServerScriptService.CommandsMain.CommandsManager:5: attempt to concatenate string with nil - Server - CommandsManager:5

CommandsMain (Script) Inside the ServerScriptService

local CommandManager = require(script.CommandsManager)
local actions = require(script.Actions)


game:GetService("Players").PlayerAdded:Connect(function(chatter)
	chatter.Chatted:Connect(function(message)
		if (message:sub(1,1) == "!") then
			local tabL = message:split(" ")
			tabL[1] = tabL[1]:lower()
			
			CommandManager.add{tabL, chatter, "speed", {true, true, true, true, false}, actions.speed}
			CommandManager.add{tabL, chatter, "jumppower", {true, true, true, true, false}, actions.jump_power}
			CommandManager.add{tabL, chatter, "setHeatlh", {true, true, true, true, false}, actions.setHealth}
			CommandManager.add{tabL, chatter, "setGrav", {true, true, true, true, false}, actions.setGrav}
			CommandManager.add{tabL, chatter, "heal", {true, true, true, true, false}, actions.heal}
			CommandManager.add{tabL, chatter, "kill", {true, true, true, true, false}, actions.kill}
			CommandManager.add{tabL, chatter, "damage", {true, true, true, true, false}, actions.damage}
			CommandManager.add{tabL, chatter, "reset", {true, true, true, true, false}, actions.reset}
			-- If you really want to, you can make the command from inside:
			CommandManager.add{tabL, chatter, "kick", {true, true, true, true, false}, function(plr, arg2)
				plr:Kick("You've been kicked using admin commands")
			end}

		end
	end)
end)

Action (ModuleScript) Inside the Commands Main script)

local actions = {}

function getCharacter(plr)
	return (plr.Character or plr.CharacterAdded:Wait())
end

actions.speed = function(plr, speed)
	if(tonumber(speed)) then
		local char = getCharacter(plr)
		char:WaitForChild("Humanoid").Walkspped = tonumber(speed)
	end
end

actions.jump_power = function(plr, value)
	if(tonumber(value)) then
		local char = getCharacter(plr)
		char:WatiForChild("Humanoid").JumpPower = tonumber(value)
	end
end

actions.setHealth = function(plr, health)
	if(tonumber(health)) then
		local char = getCharacter(plr)
		char:WaitForChild("Humandoid").Health = tonumber(health)
	end
end

actions.setGrav = function(plr, grav)
	if(tonumber(grav)) then
		workspace.Gravity = tonumber(grav)
	end
end

actions.heal = function(plr)
		local char = getCharacter(plr)
		char:WatiForChild("Humanoid").Health = char:WaitForChild("Humanoid").MaxHealth
end

actions.kill = function(plr)
	local char = getCharacter(plr)
	char:WaitForChild("Humanoid").Health = 0
end
	
actions.damage = function(plr, value)
	if(tonumber(value)) then
		local char = getCharacter(plr)
		char:WatiForChild("Humanoid").Health = char:WaitForChild("Humanoid").Health - tonumber(value)
	end
end

actions.reset = function(plr)
	plr:LoadCharacter()
end

return actions

CommandsManager (Module Script) Inside the Commands Main

local CommandManager = {}

function CommandManager.add(tabL, plr, trigger, affectsWho, func, list)
    warn(tabL,tostring(plr),trigger)	
[ERROR OCCURS HERE]	if(tabL[1] == "!" .. trigger) then
		if (tabL[1] == "!" .. trigger) == not nil then
			if(tabL[2] == nil and affectsWho[1]) then
				func(plr)
			elseif(tonumber((tabL[2])) ~= nil and affectsWho[1]) then
				func(plr, tabL[2])
			elseif(tabL[2] ~= "me" and tabL[2] ~= "others" and tabL[2] ~= "all" and not CommandManager:FindPlayer(tabL[2]:lower()) and affectsWho[1]) then
				func(plr, tabL[3])
			elseif(tabL[2] == "me" and affectsWho[1]) then
				func(plr, tabL[3])
			elseif(tabL[2] == "all" and affectsWho[2]) then
				for i,v in pairs(game:GetService("Players"):GetPlayers()) do 
					func(v)
				end
			elseif(tabL[2] == "others" and affectsWho[3]) then
				for i,v in pairs(game:GetService("Players"):GetPlayers()) do
					if(plr ~= v) then
						func(v)
					end
				end
			elseif(tabL[2] ~= "me" and tabL[2] ~= "others" and tabL[2] ~= "all" and affectsWho[4]) then

				local cPlr = CommandManager:FindPlayer(tabL[2])
				if(cPlr) then
					func(cPlr, tabL[3])
				end
			elseif(affectsWho[5] and not affectsWho[1]) then

				func(plr)
			end
			
		end
		
	end
	
end
		

-- find player from a short name
function CommandManager:FindPlayer(who)
	if (type(who) == "string") then
		who = who:lower()
		for i,v in pairs(game:GetService("Players"):GetPlayers()) do
			local name = v.Name:lower()
			if(name:sub(1, #who) == who) then
				print("Found: " .. name)
			end
		end
	end 
end
return CommandManager
1 Like

What does this print?
The error seems to suggest ‘trigger’ is nil, and not a string.

My guess is you should do:
CommandManager.add(tabL, chatter, “speed”, {true, true, true, true, false}, actions.speed)
instead of
CommandManager.add{tabL, chatter, “speed”, {true, true, true, true, false}, actions.speed}

Also in the line below the error:

if (tabL[1] == "!" .. trigger) == not nil then
--should be
if (tabL[1] == "!" .. trigger) ~= nil then

actually, (tabL[1] == “!” … trigger) is either false or true, never nil.
So the real solution is to remove that if statement all together.

Maybe you ment to write:

if (tabL[1] == "!" .. trigger) then

But as it is right now, the whole if statement is redundant and will always be true.

Writing “== not” will give u a headace from all the bugs in the future, just never do that.

I have done what you said, and that fixed it! But there is 1 problem. When I go ahead and do !speed me 100 It prints this: Walkspeed is not a valid member of Model “Workspace.Mashmello_06” I also spelt Walkspeed wrong, I fixed it. (This is the new line of code,

actions.speed = function(plr, speed)
	if(tonumber(speed)) then
		local char = getCharacter(plr)
		[ERROR OCCURS HERE] char:WaitForChild("Humanoid").Walkspeed = tonumber(speed)
	end
end  

Try changing the Walkspeed to WalkSpeed.

Walkspeed is not a vaild member of “Workspace[plr.Name]”
so, use

char:WaitForChild("Humanoid").WalkSpeed = tonumber(speed)

instead of

char:WaitForChild("Humanoid").Walkspeed = tonumber(speed)

I have fixed it, and it now works! Now I all other commands won’t work. The error that is printed is
ServerScriptService.CommandsMain.CommandsManager:5: attempt to concatenate string with nil It’s the same line of code that was causing problems as before.

	if(tabL[1] == "!" .. trigger) then

(It’s the 5th line in the CommandsManager, the same as before)

Because on all other lines you still do
CommandManager.add{ …}
instead of
CommandManager.add( … )

1 Like

Thank you, you were a big help!