Error when trying to set player healthSolved

Why this command not work?

Failed to call hook 'cmdChatHp' on plugin 'plugin v0.1.0' (IndexOutOfRangeException: Index was outside the bounds of the array.)
at Oxide.Plugins.PeacePanel.cmdChatHp (BasePlayer player, System.String command, System.String[] args) [0x0000c] in <92822096f10e442fb81c525aeed0093d>:0
at Oxide.Plugins.PeacePanel.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x004b3] in <92822096f10e442fb81c525aeed0093d>:0
at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <8a646463979e4a1d9c0e2f1298e9483f>:0
at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <953329caf7d943cc9eca5c8b4b890c98>:0
at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <953329caf7d943cc9eca5c8b4b890c98>:0

error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer
	[ChatCommand("hp")]
        void cmdChatHp(BasePlayer player, string command, string[] args)
        {
				player.Health = 40f;

        }

if i add this

float health = player.Health;

command work, and i have errors indexer

Health is a method and you cannot assign a value to a method. try player._health = 40f.
Hello, thanky for help :)
This not work for me(
i create new work code :)

Merged post

I have one question, how fix this error?
IndexOutOfRangeException: Index was outside the bounds of the array
[ChatCommand("hp")]
        void cmdChatHp(BasePlayer player, string command, string[] args)
        {
			if (!player.IsAdmin) return;
				string name = args[0];
				float hp = float.Parse(args[1]);
			if(name.Length == 0) {
				Player.Message(player,"<color=red>error 1</color>","[INFO]",123);
			} else {
				BasePlayer target = FindBasePlayer(name);
					float health = target.health;
					target.health = hp;


			
			}
        } ​
Obviously there are not enough arguments, that's what it says - index is out of bounds.

Thanks cap :D, instead of an error should be my message.

if i put this command /hp

<color=red>error 1</color>

instead, I get a global error. And if i use this comman for me, this work. If other players i have error.

If you want a working example (although universal), take a look at the Healer plugin. https://umod.org/plugins/healer

Otherwise:
[ChatCommand("hp")]
void cmdChatHp(BasePlayer player, string command, string[] args)
{
    if (!player.IsAdmin)
    {
        return;
    }

    if (args.Length >= 2)
    {
		float hp;
        BasePlayer target = FindBasePlayer(args[0]);
		if (target != null && float.TryParse(args[1], out hp))
		{
			target.health = hp;
		}
    }
	else
	{
        Player.Message(player, "<color=red>Sorry bud, that ain't right</color>");
    }
}​
Wulf, thanks for help, this a great example :)
I create my first script and i add more commands in future)

Merged post

suddenly someone will need
change this
float.TryParse(args[1], hp)​

to 

float.TryParse(args[1], out hp)
Yup, missed that. :)
Locked automatically