Help needed with displaying one specific player's health on a gui viewable to all players

Hi, so I am trying to make a health display for my game and I will first explain what my goals are.
So, I have a gui frame set up for a specific player’s health (there is a background frame and the health display frame inside the background which it’s(health display frame) size will change based on that specific player’s health) and there is a local script inside the health display frame which will update the gui whenever the specific player’s humanoid is damaged. This specific player, to make it more simple, is like a boss and for example I’ll say there is a boss fight and all player’s must fight this boss which is a randomly selected player in the game. The boss’s health is displayed in this gui to all players (including the boss) so they can see how much of his health remains. I’ve got it to work but it only displays on the boss’s screen and not the rest of the players. Does anyone know how I can fix this so that it can display on all clients?

Here is the code inside the local script (note: in a leaderstats script I have set up I make a new folder inside the player called “CheckButter” and then create a BoolValue inside that folder called “BoolCheck” and if the player is selected to be the boss then their BoolCheck value is set to true. Also I’m not sure if this affects anything but I have the script disabled until someone is randomly selected as the boss then I find the script in their playergui and enable it and I double checked in my tests to make sure it actually enabled the script and it does and I see the prints show in the output window as well.)

local player = game.Players.LocalPlayer
local frame = script.Parent

local function onHealthChanged()
	local human = player.Character.Humanoid
	local percent = human.Health / human.MaxHealth
	
	frame.Size = UDim2.new(percent, 0, 1, 0)
end

local function onCharacterAdded(character)
	print("It works this far")
	local human = character:WaitForChild("Humanoid")

	human.HealthChanged:Connect(onHealthChanged)
	onHealthChanged()
end

player.CharacterAdded:Connect(onCharacterAdded)
if player.Character and player.CheckButter.BoolCheck.Value == true then
	print("found check for butter")
	onCharacterAdded(player.Character)
end

Use a script instead of a local script, and change LocalPlayer to the boss.

but aren’t guis supposed to only be managed inside local scripts?

Not necessarily, you can change the UI of any player using a normal script.

Well is there any way I could do this from the local script?

You can use a remote event, I guess. But I think it is easier to just make a normal script.

Serverscripts cannot edit PlayerGuis, unless they’ve been there from default (they never are.). StarterGui only replicates the guis to playerguis locally, so serverscript cannot access it, and ideal way to do this is using a remote event and :FireAllClients (RemoteEvent | Roblox Creator Documentation) to edit players uis.

PlayerGuis can be edited from a script outside PlayerGui (I’ve done it multiple times.)

1 Like

Thanks for clarifying, I was unaware of that. And I am sorry for “misleading”.

Wait, it is possible? Who is correct?

If scripts inside PlayerGui can access it there is no reason for it to be locked to those scripts only.

1 Like

Yeah, that makes sense, and I am pretty sure I have done it before.

If you’re using a local script that is

It’s a common misconception that guis are not replicated from StarterGui on the server however they are since scripts can’t run inside if not. The only guid that aren’t are Roblox made guis.

I think you can edit a player’s playerGui by doing something like this

player:WaitForChild("PlayerGui")
2 Likes

Serverscripts cannot edit PlayerGuis

Look at the documentation, notice there is no [notReplicated] visible:

The only thing that caused this misinformation is that this came up on a previous development discussion: While better performance-wise to use localscripts, normal scripts can be used and normal scripts should be used when local scripts cannot or when code needs to be hidden.

1 Like

You could use a bindable event and have it update the GUIs each time the player is damaged.

well I just wanted to let all of you know I appreciate all your help and answers and insight but I got it working now. So I always have this local script disabled until someone is randomly selected the boss and when they are this local script for them only is enabled so whenever they are hit and damage is done it fires a remote event to a server script which picks it up and as soon as it does it fires another remote event from there to another local script that is always enabled for all players that updates the gui and this seems to work. If there is any other way to do this you can post it here I would love to see other options and I’m sure others would too for anyone else that may see this in the future.