Health only works after resetting character

In my game the player’s health increases when they get more of a certain stat but the custom health amount only works after resetting your character once after joining the game.

player.CharacterAppearanceLoaded:Connect(function(character)
		print("character loaded")
		local humanoid = character.Humanoid
		humanoid.MaxHealth = 100 * (power.Value / 5)
		humanoid.Health = 100 * (power.Value / 5)
		humanoid.WalkSpeed = 16 + (rebirths.Value)
		
		power:GetPropertyChangedSignal("Value"):Connect(function()
			humanoid.MaxHealth = 100 * (power.Value / 5)
			humanoid.WalkSpeed = 16 + (rebirths.Value)
		end)
	end)

Guessing that this connection is made after the first CharacterAppearanceLoaded event fires, so you could get around this by creating a named function then calling it upon first character appearance loaded, and then after the appearance loaded.

local function characterAppearanceLoaded(character)
    -- do stuff with the character
end

if player:HasAppearanceLoaded() then
    characterAppearanceLoaded(player.Character)
end

player.CharacterAppearanceLoaded:Connect(characterAppearanceLoaded)

Thank you, I did some testing and it seems to be fixed now!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.