Set Health script

So I’m trying to make a native where whenever someone joins my server it sets their HP to 200 instead of the 150 HP that it gives you. I’ve tried a couple of stuff and this error keeps popping up.

SCRIPT ERROR: @health/cl_health.lua:4: attempt to call a nil value (global ‘SetPlayerHealth’)

I’ve searched the Forums and I can’t find any information regarding this so I’ll just leave this here and hope someone helps.

The script/resource that I’ve made is this:

Citizen.CreateThread(function()
     while true do
          Citizen.Wait(0)
          SetPlayerHealth(GetPlayerPed(-1), 200.0)
     end
end)

Maybe u can check to use SET_ENTITY_HEALTH

Tried that and whenever I die it just “revives” me instantly, can’t use the weapon wheel and it breaks vMenu as well :confused:

That’s because you’re just looping through that code repeatedly. You need to just run the native once when the player spawns.

Found the solution and it works fine, I used both SetEntityHealth and SetEntityMaxHealth and it works fine now. Thanks for all the replies :slight_smile: .

Citizen.CreateThread(function()
     do
	      Citizen.Wait (0)
		  SetEntityHealth(GetPlayerPed(-1), 300)
          SetEntityMaxHealth(GetPlayerPed(-1), 200)
     end
end)