Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to prevent Health billboard gui disappear after respawn?

game.Players.ChildAdded:connect(function(player)
	player.CharacterAdded:connect(function(char)
		local plyrGuiH = Instance.new("BillboardGui")
		plyrGuiH.Name = "HealthOverlay"
		plyrGuiH.Parent = char.Head
		plyrGuiH.Adornee = char.Head
		plyrGuiH.Size = UDim2.new (1,0,1,0,0,0)
		plyrGuiH.StudsOffset = Vector3.new (0,1.2,0)
		--plyrGuiH.PlayerToHideFrom = player
		
		local frame = Instance.new("Frame")
		frame.Parent = plyrGuiH
		frame.Size = UDim2.new (0,180,0,10)
		frame.BackgroundColor3 = Color3.fromRGB (9, 33, 49)
		
		local overlay = Instance.new("Frame")
		overlay.Parent = frame
		overlay.Name = "Overlay"
		overlay.BackgroundColor3 = Color3.fromRGB (255, 24, 58)
		overlay.Size = UDim2.new (0,180,0,10)
		
	game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)
	local players = game.Players.LocalPlayer
	repeat wait() until players.Character
	local Humanoid = players.Character:WaitForChild("Humanoid")
	local HealthMath = Humanoid.Health / (Humanoid.MaxHealth)
	
	script.Parent = overlay
	script.Parent:TweenSize(UDim2.new(HealthMath, 0, 1, 0), "Out", "Sine", .5)

	Humanoid.HealthChanged:connect(function()
		local HealthMath = Humanoid.Health / (Humanoid.MaxHealth)
		script.Parent:TweenSize(UDim2.new(HealthMath, 0, 1, 0), "Out", "Sine", .5)
	end)

		
	end)
end)

When enter the game, the billboard is there , but after reset the character it is gone.

3 comments

0

Suggest parenting it inside of PlayerGui, setting it to not reset on respawn, and adornee it to the head as you already do.

0

Still disappear :c

0

You gotta set the adornee again when a new character gets added, since the old Head is gone.

2 answers

✓ Accepted answer

You were setting the script's parent to the gui object, so when the player resets, the script is destroyed, severing the connections of the listeners in it.

I also recommend you use a serverscript and put it in ServerScriptService instead.

(Also if you need help centering the GUI and locking it's size, let me know)

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(char)
        local plyrGuiH = Instance.new("BillboardGui")
        plyrGuiH.Name = "HealthOverlay"
        plyrGuiH.Parent = char.Head
        plyrGuiH.Adornee = char.Head
        plyrGuiH.Size = UDim2.new (1,0,1,0,0,0)
        plyrGuiH.StudsOffset = Vector3.new (0,1.2,0)
        --plyrGuiH.PlayerToHideFrom = player

        local frame = Instance.new("Frame")
        frame.Parent = plyrGuiH
        frame.Size = UDim2.new (0,180,0,10)
        frame.BackgroundColor3 = Color3.fromRGB (9, 33, 49)

        local overlay = Instance.new("Frame")
        overlay.Parent = frame
        overlay.Name = "Overlay"
        overlay.BackgroundColor3 = Color3.fromRGB (255, 24, 58)
        overlay.Size = UDim2.new (0,180,0,10)

    game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)
    local Humanoid = player.Character:WaitForChild("Humanoid")
    local HealthMath = Humanoid.Health / (Humanoid.MaxHealth)
	wait()
    overlay:TweenSize(UDim2.new(HealthMath, 0, 1, 0), "Out", "Sine", .5)

    Humanoid.HealthChanged:connect(function()
        local HealthMath = Humanoid.Health / (Humanoid.MaxHealth)
      	overlay:TweenSize(UDim2.new(HealthMath, 0, 1, 0), "Out", "Sine", .5)
    end)

    end)
end)


1 comment

0

Ohh I see!! Thank you very muchh!! I need your help with the glitching part of the gui too and I think I do need your help how to center the Gui and locking it's size. It would be nice of you to help me with that x3 I'm still learning scripting. :D

Just go to the ScreenGui, click it, and make the ResetOnSpawn property false. I used to have the same problem.

This discussion is preserved as it was. New answers, comments, and votes are closed.