How can i set a new default HP amount?

i’ve tried editing the default Health script, but it’s not reliable and only works like 1/10 times.

1 Like

There are a few ways to do this!

One way is to place a server script in StarterCharacterScripts to set a new default health value, this will also work coherently with the default health regeneration script.

local DEFAULT_HEALTH = 1000

local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")

Humanoid.Health = DEFAULT_HEALTH
Humanoid.MaxHealth = DEFAULT_HEALTH

I want to be able to set it to the value of an IntValue parented to the player. How can I do that?

In light of this, we can reference that value object directly and then set the DEFAULT_HEALTH constant to the value of that int object.

Keep in mind, your current parent of this script is the character.

1 Like

Server Script on ServerScriptService

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function()
      plr.Character.Humanoid.MaxHealth = plr.Character.IntValueName.Value
      plr.Character.Humanoid.Health = plr.Character.IntValueName.Value
   end)
end)
1 Like

yeah but you should add a player.CharacterAdded event to it

I already added, I see that I forgot when I reply

Is there a good way to detect when the Value has fully loaded?

what do you mean detect when it is fully loaded

It loads each time the character load, so the script I gived may work

the int value is changed by a datastore when the player joins. i want it to fully wait until the number in the int value has loaded.

I think you are referring to ensuring it exists before trying to reference it.

You can do this, and it’s good practice to do so to avoid any null reference errors!

Also, to ensure we account for changes that happen to the value should we load in faster than our data is set; we can use :GetPropertyChangedSignal() to listen for a change to specifically the value property of the IntValue.

local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")

local Player = game:GetService("Players"):GetPlayerFromCharacter(Character)

if Player then
   local HealthValue = Player:WaitForChild("NAME_OF_INT_VALUE")

   Humanoid.Health = HealthValue.Value
   Humanoid.MaxHealth = HealthValue.Value

   HealthValue:GetPropertyChangedSignal("Value"):Connect(function()
       Humanoid.Health = HealthValue.Value
       Humanoid.MaxHealth = HealthValue.Value
   end)
end
1 Like