I have a custom health GUI that I modified from a free model to my own liking, but now I've noticed an issue. I don't want the GUI to reset when the player dies, but the problem with setting ResetPlayerGuiOnSpawn to false makes it so the health bar localscript loses the Humanoid association, which leaves the health bar at 0.
local Player = game.Players.LocalPlayer
repeat wait() until Player.Character
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
function ChangeSize(Front, DifferenceBar, Algorithm)
Front:TweenSize(UDim2.new(Algorithm, 0, 1, 0), "Out", "Linear", 0.5, true)
wait(0.5) --btw is this safe to use?
DifferenceBar.Size = UDim2.new(Algorithm, 0, 1, 0)
end
Humanoid.HealthChanged:connect(function(Health)
local MaxHealth = Humanoid.MaxHealth
local Algorithm = (Health / (MaxHealth))
script.Parent.HPText.Text = math.floor(Humanoid.Health+0.5).. "/"..math.floor(Humanoid.MaxHealth+0.5).. " "
ChangeSize(script.Parent.Back.Front, script.Parent.Back.DifferenceBar, Algorithm)
end)
How can I grab the player's humanoid when they spawn again without resetting the GUI?

2 comments
Hey, that works! The only problem I have with this however is that the health bar only works after the player dies once. Before, nothing inside the function runs.
Wait never mind it works now after I moved some code into the function. Thanks!