Trying to make an boss Health Bar that disappears when boss mob which the health bar has copied it's contents from dies

hello there, I ask for help again on scripting support channel for find someone who could help me with Boss Health Bar GUI, I have attempted to create an boss Health GUI based off from this another forum topic post, here is the hyperlink of that topic post: To the sorbiouse’s forum topic about boss health bar GUI

  1. What I want to achieve: I want to make the contents inside the BillBoardGui inside the humanoid named “Enemy” thatt is inside Boss character’s model gets copied inside PlayerGui.BossHealthBarCopyGui.BossHealthBarFrame
    and I also want when the boss mob of that boss health bar does dies, I want the remaining contents that has been copied from the billboardGui to Destroy() itself…

  2. *but the issue is that the script I will show you below would not work in that order… I have no idea why that codes wouldn’t work as intended… :sob: *

  3. **I have tried to run the game multiple times and pasted the contents on the billboardgui inside the humanoid of that enemy boss mob to see if it works, but it did not worked well again…

now I will show you these script codes below, I will be waiting to find some peoples to help me with it :face_holding_back_tears:

-- this script is located in Workspace.Mobs.GigantiumGoblin.Enemy.Script
local Mob = script.Parent
local Enemy = Mob.Enemy
local player = game.Players.LocalPlayer
local playerBossHealthBarGUI = player.PlayerGui:WaitForChild("BossHealthBarCopyGui").BossHealthBarFrame
local signal = Enemy:GetPropertyChangedSignal("Health"):Connect(function()
end)
local deathsig = boss.Humanoid.Died:Connect(function()
	signal:Disconnect()
end)
deathsig:Disconnect()
boss = nil

Enemy.HealthChanged:Connect(function()
	local BossHealthBarCopy = script.Parent.BillboardGui:GetChildren()
	for i,v in pairs(BossHealthBarCopy:GetChildren()) do
		v:Clone()
		v.Parent = playerBossHealthBarGUI

		if signal:Disconnect() then
			for i,v in pairs(playerBossHealthBarGUI:GetChildren()) do
				v:Destroy()
			end
		end
	end
end)

thanks for reading all of this topic posts, it helps me a lot ;> - mari

2 Likes

I think you might be going about this from a very difficult angle. Because you’re trying to create a Boss Health Bar on the Player’s screen, you’re probably better off making this script under the Player instead of the Boss.

That’s actually how MallocByte structured his code if you look at his post.

What I can suggest to do first is to create a LocalScript under StarterPlayer > StarterPlayerScripts to make handling the Gui super duper easy. In this script we can set up some variables to keep track of the components in the Gui, and when the boss health updates we update the visuals accordingly.

local player = game.Players.LocalPlayer
local bossHealthBarGui = player.PlayerGui:WaitForChild("BossHealthBarCopyGui")
local healthFrame = bossHealthBarGui.BossHealthBarFrame

-- We don't need to create a clone of the boss health bar unless there will be multiple bosses at the same time

-- Keep track of boss components --
local boss = workspace:WaitForChild("Mobs").GigantiumGoblin
local bossHumanoid = boss.Humanoid

local bossHealthChangedConnection = bossHumanoid.HealthChanged:Connect(function()
	-- Code in here will run each time the Boss health changes --
	-- So, you want to update the Gui here --
	print("Boss Health Changed!")
end)

-- The code inside here will run when the Boss dies --
bossHumanoid.Died:Once(function()
	bossHealthChangedConnection:Disconnect() -- Disconnect event we don't need anymore --
	bossHealthBarGui.Enabled = false -- Hide the Health Bar when the Boss dies --
	print("Boss has Died!")
end)

This code will run once, and immediately when the Player joins the game. But I think for now if you can get this working you have a base for implementing a more complex system!

1 Like

and also the functionality of the gui

local function updateHealthBar()
    local healthRatio = humanoid.Health / humanoid.MaxHealth
    healthBar.Size = UDim2.new(healthRatio, 0, 1, 0)
end

The :Disconnect() method currently always returns nil so the code inside of that if statement will never run since nil is treated equivalent to false in the context of if statements (under normal conditions, unless your write == nil for example)

1 Like

hello there, I have tried my best to modify the localscript inside startercharacterscripts to work efficiently with less errors, and I have made this lines of codes, here is the code shown on the below, and I will explain about the remaining errors with this gui.

local TweenService = game:GetService("TweenService")
local Stepped = game:GetService("RunService").Stepped
local Abb = require(game.ReplicatedStorage.ShortenNumber)
local player = game.Players.LocalPlayer
local bossHealthBarGui = player.PlayerGui:WaitForChild("BossHealthBarCopyGui")
local healthFrame = bossHealthBarGui.BossHealthBarFrame
local healthBar = healthFrame.HealthInfo.HealthBar

-- We don't need to create a clone of the boss health bar unless there will be multiple bosses at the same time

-- Keep track of boss components --
local boss = workspace:WaitForChild("Mobs").GigantiumGoblin
local bossHumanoid = boss.Enemy

local bossHealthChangedConnection = bossHumanoid.HealthChanged:Connect(function() --I want this script makes it so this gui only appears when player get near the boss or it will instantly disappear until player encounters an boss
	-- Code in here will run each time the Boss health changes --
	-- So, you want to update the Gui here (** in the code line 18 ~ 36, I put an boss health bar script code from the original game I am working on**) --
	bossHealthBarGui.Enabled = true
		local HBT = TweenService:Create(healthBar.Fill, TweenInfo.new(1.5/4, Enum.EasingStyle.Quint, Enum.EasingDirection.Out), {Size = UDim2.new(bossHumanoid.Health / bossHumanoid.MaxHealth,0,1,0)
	})HBT:Play()
	healthBar.Health.Text = Abb.Abb2(bossHumanoid.Health) .."/".. Abb.Abb2(bossHumanoid.MaxHealth)
	healthBar.Percentage.Text = math.floor(bossHumanoid.Health / bossHumanoid.MaxHealth * 100) .. "%"

	if bossHumanoid.Health <= bossHumanoid.MaxHealth * 0.33 then
		local CT1 = TweenService:Create(healthBar.Fill, TweenInfo.new(3/4, Enum.EasingStyle.Quint, Enum.EasingDirection.Out), {BackgroundColor3 = script.Low.Value
		})CT1:Play()

	elseif bossHumanoid.Health <= bossHumanoid.MaxHealth * 0.66 and bossHumanoid.Health >= bossHumanoid.MaxHealth * 0.33 then
		local CT2 = TweenService:Create(healthBar.Fill, TweenInfo.new(3/4, Enum.EasingStyle.Quint, Enum.EasingDirection.Out), {BackgroundColor3 = script.Medium.Value
		})CT2:Play()
	else
		local CT3 = TweenService:Create(healthBar.Fill, TweenInfo.new(3/4, Enum.EasingStyle.Quint, Enum.EasingDirection.Out), {BackgroundColor3 = script.High.Value
		})CT3:Play()
	end
end)

-- The code inside here will run when the Boss dies --
bossHumanoid.Died:Once(function()
	bossHealthChangedConnection:Disconnect() -- Disconnect event we don't need anymore --
	bossHealthBarGui.Enabled = false -- Hide the Health Bar when the Boss dies --
	print("Boss has Died!")
end)

so the remaining issues with my script is that when player enters the portal, the gui that was not enabled will somehow get enabled and boss health bar gui will be shown even if player has not damaged or encountered an boss… so what I wish I could do to fix my script codes is to make it so when player has not damaged the boss, the gui will continuously go invisible until player damages an boss then it will stay visible until player go out of specified range written inside script or player kills an boss, the gui will disenabled, and then when player damages the same boss again, it will be enabled again.

other then this current issues, the boss health bar gui does update whenever boss mob’s health has been modified, hopefully someone (and maybe you) could help me out with an script again :pleading_face:

(and the video recordings capturing detailing about the boss healthbar Gui issue

Hi,

Since I’m feeling sick right now, I might not be able to help you until the weekends or someone else could help you. Hope you understand

1 Like