I need help on getting my game to display another player's Health/Name in a GUI to other certain players

Hello!
Firstly, Apologies if this may come out confusing, i’am trying to explain what I want/am trying to do to the best of my ability.

I’am working on an RPG game and I’am trying to make a GUI that will display the Health/AP/Name of a player to others players based on what Battle Scenario they’re in and what position each player joins in a Battle.

I’ve managed to make one that works for myself.
image

My Idea is to Use 2 different Number Values that decides What and How players see other player’s Health.
One named ‘BattleID’ that determines what Battle Room the player is in, and another named BattlePlacement that determines what Player Position the player is in upon joining I.E: 1-4.

How can I get my game to display the Names/Health of other players to a person’s screen based on what BattleID Value a player has, and what The PositionValue of each player is upon joining in a battle.

The result I’am trying to accomplish is something like this…

1 Like

Why not fetch all of the players then get their characters then attach a function that changes the size of your UI’s based on changes in the Humanoid’s health?

First off I just want to say that I won’t give you a direct answer but provide you with some guidance. There is a lot you are asking in this post but I think giving you a place to start off would be of use. You can always ask more questions later.

Issue One

For this I would use a UIListLayout and set the FillDirection property to Horizontal. This will automatically position the UI to not overlap with each other.

Issue Two

For this you can reley on the .Changed Event on each player’s Humanoid.Health. When this event fires send the health value and username of the player to each client using a RemoteEvent. Now to modify the data on each player’s screen you will need a LocalScript to listen for the information.

Err I don’t really know how to get/fetch all of the players, I’am still fairly new to scripting on Roblox. Also I’am using Number Values for players Health*.

Oh so you can do game:GetService("Players):GetPlayers() to get a list of all players in the server. From there you can check if the player’s number value or whatever matches whatever the client’s number value is and then do Player.Character.Humanoid to get the humanoid.

Humanoids have a HealthChanged event so use that to update the healthbars

Should checking if the player’s number value matches the client’s value be done in a local script?

Because this is all just in an GUI and you’re only trying to read the values, this should all be done in a Local Script

Okay…I think I’m almost there…
image
Although I am stuck on getting the Name/HP/AP TextLabels for Player 1 to change.

for _,i in pairs (game:GetService("Players"):GetPlayers()) do

	while true do
	wait(0.01)	
	---------------//Placement 1\\------------------
if i.BattleID.Value == 1 and i.BattlePlacement.Value == 1 then	

	local Hud1 = script.Parent.HUD1
		print("Player 1 found")
			---------------------<Ap Counter>----------------------
		local APCounter1 = Hud1.APCounter
	
		APCounter1.Text = i.Character.AbilityPointsCounter.Value
		
		-----------------<Health Points Counter>---------------
		local HPCounter1 = Hud1.HPCounter
		HPCounter1.Text = i.Character.HealthPointsCounter.Value
		
		--------------------<Player Name>----------------------
		local PlayerName1 = Hud1.PlayerName
		PlayerName1.Text = i.Name
		
		
		
	else
			print("Player 1 not found yet...")
			
			
	
		end
		
		--------------//Placement 2\\-------------
if i.BattleID.Value == 1 and i.BattlePlacement.Value == 2 then	

	local Hud2 = script.Parent.HUD2
		print("Player 2 found")
			---------------------<Ap Counter>----------------------
		local APCounter2 = Hud2.APCounter
	
		APCounter2.Text = i.Character.AbilityPointsCounter.Value
		
		-----------------<Health Points Counter>---------------
		local HPCounter2 = Hud2.HPCounter
		HPCounter2.Text = i.Character.HealthPointsCounter.Value
		
		--------------------<Player Name>----------------------
		local PlayerName2 = Hud2.PlayerName
		PlayerName2.Text = i.Name
		
		
		
	else
			print("Player 2 not found yet...")
	end
	---------------//Placement 3\\---------------
if i.BattleID.Value == 1 and i.BattlePlacement.Value == 3 then	

	local Hud3 = script.Parent.HUD3
		print("Player 3 found")
			---------------------<Ap Counter>----------------------
		local APCounter3 = Hud3.APCounter
	
		APCounter3.Text = i.Character.AbilityPointsCounter.Value
		
		-----------------<Health Points Counter>---------------
		local HPCounter3 = Hud3.HPCounter
		HPCounter3.Text = i.Character.HealthPointsCounter.Value
		
		--------------------<Player Name>----------------------
		local PlayerName3 = Hud3.PlayerName
		PlayerName3.Text = i.Name
		
		
		
	else
			print("Player 3 not found yet...")	
		end
		------------//Placement 4\\-----------------
if i.BattleID.Value == 1 and i.BattlePlacement.Value == 4 then	

	local Hud4 = script.Parent.HUD4
		print("Player 4 found")
			---------------------<Ap Counter>----------------------
		local APCounter4 = Hud4.APCounter
	
		APCounter4.Text = i.Character.AbilityPointsCounter.Value
		
		-----------------<Health Points Counter>---------------
		local HPCounter4 = Hud4.HPCounter
		HPCounter4.Text = i.Character.HealthPointsCounter.Value
		
		--------------------<Player Name>----------------------
		local PlayerName4 = Hud4.PlayerName
		PlayerName4.Text = i.Name
		
		
		
		else
			print ("Player 4 not found yet...")
			
		end
	end
	end

This is the Local Script that I used

1 Like

Do not use a while loop. Use a function connected to an event.

for you it would be

i.Character.Humanoid.HealthChanged:Connect(function()
   --Change the UI
end)

You also should not be comparing each battleplacement individually. Just do

local HUD = script.Parent:FindFirstChild("HUD"..i.BattleID.Value)
1 Like

I seem to be getting an output error from.

i.Character.Humanoid.HealthChanged:Connect(function()

Humanoid is not a valid member of Model

you may have to yield for the character.

Okay I changed up my script to the best of my understanding…

for _,i in pairs (game:GetService("Players"):GetPlayers()) do
i.Character.Humanoid:Connect(function()
------------------------------//Placement 1\\---------------------------------
	
	

	local Hud1 = script.Parent:FindFirstChild("HUD1"..i.BattleID.Value)
		print("Player 1 found")
			---------------------<Ap Counter>----------------------
		local APCounter1 = script.Parent
	
		APCounter1.Text = i.Character.AbilityPointsCounter.Value
		
		-----------------<Health Points Counter>---------------
		local HPCounter1 = script.Parent.HPCounter
		HPCounter1.Text = i.Character.HealthPointsCounter.Value
		
		--------------------<Player Name>----------------------
		local PlayerName1 = script.Parent.PlayerName
		PlayerName1.Text = i.Name
		
		------------------------------//Placement 2\\---------------------------------
	
	

	local Hud2 = script.Parent:FindFirstChild("HUD2"..i.BattleID.Value)
		print("Player 1 found")
			---------------------<Ap Counter>----------------------
		local APCounter1 = script.Parent
	
		APCounter1.Text = i.Character.AbilityPointsCounter.Value
		
		-----------------<Health Points Counter>---------------
		local HPCounter1 = script.Parent.HPCounter
		HPCounter1.Text = i.Character.HealthPointsCounter.Value
		
		--------------------<Player Name>----------------------
		local PlayerName1 = script.Parent.PlayerName
		PlayerName1.Text = i.Name
		
		------------------------------//Placement 3\\---------------------------------
	
	

	local Hud3 = script.Parent:FindFirstChild("HUD3"..i.BattleID.Value)
		print("Player 1 found")
			---------------------<Ap Counter>----------------------
		local APCounter1 = script.Parent
	
		APCounter1.Text = i.Character.AbilityPointsCounter.Value
		
		-----------------<Health Points Counter>---------------
		local HPCounter1 = script.Parent.HPCounter
		HPCounter1.Text = i.Character.HealthPointsCounter.Value
		
		--------------------<Player Name>----------------------
		local PlayerName1 = script.Parent.PlayerName
		PlayerName1.Text = i.Name
		
		------------------------------//Placement 4\\---------------------------------
	
	

	local Hud4 = script.Parent:FindFirstChild("HUD4"..i.BattleID.Value)
		print("Player 1 found")
			---------------------<Ap Counter>----------------------
		local APCounter1 = script.Parent
	
		APCounter1.Text = i.Character.AbilityPointsCounter.Value
		
		-----------------<Health Points Counter>---------------
		local HPCounter1 = script.Parent.HPCounter
		HPCounter1.Text = i.Character.HealthPointsCounter.Value
		
		--------------------<Player Name>----------------------
		local PlayerName1 = script.Parent.PlayerName
		PlayerName1.Text = i.Name
		
 	end)

	
end

		

	


	
	
1 Like

Unfortunately you have missed a crucial part of my explanation. You don’t need to do

You only need to create 1 HUD in a for loop and it will do every player for you.

1 Like

HealthChanged only fires if the health goes down

That is completely incorrect. I am currently using it for my healthbar and it works perfectly. In addition, the Roblox Core scripts also uses this to update their UI.

You can even check out Roblox’s very own health bar tutorial script in the HealthChanged page.