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.
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…
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
Okay…I think I’m almost there…
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
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.