Humanoid maxHealth saving if player dies

Hello, im making a health system and need help with health saving if player dies:

  1. Currently if I reset character it gives me that warning:

RunService:UnbindFromRenderStep removed different functions with same reference name utility-focus-state-inspect-abkolia228 2 times.

I change Humanoid maxHealth and health in localscript and saving this with profile service on server script

-- Local
local PlayerHp = player:WaitForChild('PlayerValues'):WaitForChild('PlayerHp')

local Character = player.Character
local Humanoid = Character:WaitForChild('Humanoid')

local NewHealth = PlayerHp.Value
local HealthBeforeDeath

if Humanoid then
	Humanoid.MaxHealth = NewHealth
	Humanoid.Health = NewHealth
	print(Humanoid.Health)
	print(Humanoid.MaxHealth)
end

Humanoid.Died:Connect(function()
		HealthBeforeDeath = NewHealth
end)

player.CharacterAdded:Connect(function(character)
	Humanoid.MaxHealth = HealthBeforeDeath
	Humanoid.Health = HealthBeforeDeath
end)

-- Server
game.Players.PlayerAdded:Connect(function(player)
	local profile = dataManager.Profiles[player]
	if not profile then return end
	
	profile.Data.PlayerHp = player.PlayerValues.PlayerHp.Value
	print(profile.Data.PlayerHp
	
end)

This is a CoreGui warning bug, it is safe to ignore.

As for your problem, you will have to change the properties on the server instead of the client.

2 Likes

I did that on server now, but it still resets my health upon death

Question is still unsolved

It may be because you’re changing the health stuff on the client, since profileservice is on the server. the value doesn’t really exist on the server, so I advise you use remote events for this.

How can I use remote to set this data? Do I need to create a loop? I dont know how to do that.

Can’t you just do this in a server script. (I placed this is ServerScriptService)

local players = game.Players

players.PlayerAdded:Connect(function(plr)
	local plrmaxhealth
	plr.CharacterAdded:Connect(function(char)
		local humanoid : Humanoid = char.Humanoid
		if plrmaxhealth then
			humanoid.MaxHealth = plrmaxhealth
		else
			humanoid.MaxHealth = 100 --default
		end
		humanoid:GetPropertyChangedSignal("MaxHealth"):Connect(function()
			plrmaxhealth = humanoid.MaxHealth
		end)
	end)
end)

If you want the plrmaxhealth to be a NumberValue or IntValue, I can try and do that.