Adonis Command Returning Error

I am trying make a command to give someone magic however it is returning this error:
image

Here is my script:

--[[
	SERVER PLUGINS' NAMES MUST START WITH "Server: "
	CLIENT PLUGINS' NAMES MUST START WITH "Client: "
	
	Plugins have full access to the server/client tables and most variables.
	
	You can use the MakePluginEvent to use the script instead of setting up an event.
	PlayerChatted will get chats from the custom chat and nil players. 
	PlayerJoined will fire after the player finishes initial loading
	CharacterAdded will also fire after the player is loaded, it does not use the CharacterAdded event.
	
	service.HookEvent('PlayerChatted',function(msg,plr) 
		print(msg..' from '..plr.Name..' Example Plugin')
	end)
	
	service.HookEvent('PlayerJoined',function(p) 
		print(p.Name..' Joined! Example Plugin') 
	end)
	
	service.HookEvent('CharacterAdded',function(plr) 
		server.RunCommand('name',plr.Name,'BobTest Example Plugin') 
	end)
	
--]]

server = nil -- Mutes warnings about unknown globals
service = nil
return function()
	server.Commands.givemagic = {
		Prefix = server.Settings.Prefix;	-- Prefix to use for command
		Commands = {"givemagic"};	-- Commands
		Args = {"player","amount"};	-- Command arguments
		Description = "Gives a certain player an amount of magic. They must be a witch, if the amount you attempt to give them is more than their max, it will up their max.";	-- Command Description
		Hidden = false; -- Is it hidden from the command list?
		Fun = false;	-- Is it fun?
		AdminLevel = "Admins";	    -- Admin level; If using settings.CustomRanks set this to the custom rank name (eg. "Baristas")
		Function = function(plr,args)    -- Function to run for command
			print(args[1])
			print(args[2])
			local TargetPlayer = game.Players:FindFirstChild(args[1])
			local Magic = tonumber(TargetPlayer.Character.WitchStats.Magic.Value)
			local MaxMagic = tonumber(TargetPlayer.Character.WitchStats.MaxMagic.Value)
			print(MaxMagic)
			if args[2] > MaxMagic then
				MaxMagic = args[2]
				Magic = args[2]
			elseif args[2] < MaxMagic then
				local function testIfToMuch(Player,Adding)
					local currentMagic = tonumber(Player.WitchStats.Magic.Value)
					local maxMagic = tonumber(Player.WitchStats.MaxMagic.Value)
							
					local addedAmount = currentMagic + Adding
							
					if addedAmount > MaxMagic then
						return "more"
					elseif addedAmount < MaxMagic then
						return "less"
					elseif addedAmount == MaxMagic then
						return "equal"
				end
			end
								
			local test = testIfToMuch(TargetPlayer,args[2])
								
			if test == "more" then
					MaxMagic = Magic + args[2]
					Magic = args[2]
				elseif test == "less" then
					Magic = Magic + args[2]
				elseif test == "equal" then
					Magic = Magic + args[2]
				end
							
			end
		end
	}
end

Line 44 is

if args[2] > MaxMagic then

All help is appreciated! :smiley:

use

if tonumber(args[2]) > MaxMagic then

because args[2] would currently be a string so you need to change it into a number to compare.

That got rid of the errors, but it still doesn’t work…

It is because you are referencing the values and not adding to the value itself.

and you are trying to add a string to a number

I do not understand what you are saying… :confused:

1 Like

Simply like this:

--[[
	SERVER PLUGINS' NAMES MUST START WITH "Server: "
	CLIENT PLUGINS' NAMES MUST START WITH "Client: "
	
	Plugins have full access to the server/client tables and most variables.
	
	You can use the MakePluginEvent to use the script instead of setting up an event.
	PlayerChatted will get chats from the custom chat and nil players. 
	PlayerJoined will fire after the player finishes initial loading
	CharacterAdded will also fire after the player is loaded, it does not use the CharacterAdded event.
	
	service.HookEvent('PlayerChatted',function(msg,plr) 
		print(msg..' from '..plr.Name..' Example Plugin')
	end)
	
	service.HookEvent('PlayerJoined',function(p) 
		print(p.Name..' Joined! Example Plugin') 
	end)
	
	service.HookEvent('CharacterAdded',function(plr) 
		server.RunCommand('name',plr.Name,'BobTest Example Plugin') 
	end)
	
--]]

server = nil -- Mutes warnings about unknown globals
service = nil
return function()
	server.Commands.givemagic = {
		Prefix = server.Settings.Prefix;	-- Prefix to use for command
		Commands = {"givemagic"};	-- Commands
		Args = {"player","amount"};	-- Command arguments
		Description = "Gives a certain player an amount of magic. They must be a witch, if the amount you attempt to give them is more than their max, it will up their max.";	-- Command Description
		Hidden = false; -- Is it hidden from the command list?
		Fun = false;	-- Is it fun?
		AdminLevel = "Admins";	    -- Admin level; If using settings.CustomRanks set this to the custom rank name (eg. "Baristas")
		Function = function(plr,args)    -- Function to run for command
			print(args[1])
			print(args[2])
			local TargetPlayer = game.Players:FindFirstChild(args[1])
			local Magic = TargetPlayer.Character.WitchStats.Magic.Value
			local MaxMagic = TargetPlayer.Character.WitchStats.MaxMagic
			print(MaxMagic)
			if tonumber(args[2]) > MaxMagic.Value then
			elseif tonumber(args[2]) < MaxMagic.Value then
				local function testIfToMuch(Player,Adding)
					local currentMagic = Player.WitchStats.Magic
					local maxMagic = Player.WitchStats.MaxMagic
							
					local addedAmount = currentMagic.Value + Adding
							
					if addedAmount > MaxMagic.Value then
						return "more"
					elseif addedAmount < MaxMagic.Value then
						return "less"
					elseif addedAmount == MaxMagic.Value then
						return "equal"
				end
			end
								
			local test = testIfToMuch(TargetPlayer,tonumber(args[2]))
								
			if test == "more" then
					MaxMagic.Value += tonumber(args[2])
					Magic.Value = tonumber(args[2])
				elseif test == "less" then
					Magic.Value += tonumber(args[2])
				elseif test == "equal" then
					Magic.Value += tonumber(args[2])
				end
							
			end
		end
	}
end

Ok, I put that in buy still no errors. And didn’t work.

Here is what printed:
image