OverheadGui script only changes the text locally and not server side

So i have this script below, what it does is that it changes the text to show other players the hp,level and name of the player using an overhead Gui.

My issue is that for some reason the text on the Gui does not change except client sided. The only thing that actually shows on the server side is the name of the player. I want the information to be visible for everyone

client sided:
image

server sided:
image


local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UpdateOverheadGuiVisibility = ReplicatedStorage.Remotes:WaitForChild("UpdateOverheadGuiVisibility")

-- Function to update the overhead GUI for a player's character
local function updateOverheadGui(character)
	local player = Players:FindFirstChild(character.Name)
	if not player then return end
	
	local overheadGui = character:FindFirstChild("OverheadGui")
	if not overheadGui then
		overheadGui = script.OverheadGui:Clone()
		overheadGui.Parent = character.Head
		overheadGui.Name = "OverheadGui"
	end
	
	local usernameLabel = overheadGui.Background:FindFirstChild("Username")
	if usernameLabel then
		usernameLabel.Text = character.Name
	end
	
	local healthLabel = overheadGui.Background:FindFirstChild("Health")
	if healthLabel then
		local humanoid = character:FindFirstChild("Humanoid")
		if humanoid then
			healthLabel.Text = tostring(humanoid.Health)
			humanoid.HealthChanged:Connect(function(health)
				healthLabel.Text = tostring(health)
			end)
		end
	end
	
	local levelLabel = overheadGui.Background.LevelBorder:FindFirstChild("Level")
	if levelLabel then
		local playerLevel = player:GetAttribute("Level") or 1
		levelLabel.Text = tostring(playerLevel)
	end

	character.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
	character.Humanoid.HealthDisplayDistance = 0
	UpdateOverheadGuiVisibility:FireClient(player, overheadGui)
end

-- Bind the update function to player characters
local function onCharacterAdded(character)
	updateOverheadGui(character)
end

-- Bind the update function to existing players
for _, player in Players:GetPlayers() do
	player.CharacterAdded:Connect(onCharacterAdded)
	if player.Character then
		updateOverheadGui(player.Character)
	end
end

-- Bind the update function to new players
Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(onCharacterAdded)
end)

Is the script a LocalScript? LocalScripts can only display information on the client locally. Server scripts displays for everyone.

Nope, i wish that was the issue. Its a script inside of ServerScriptService.

Cant the problem be that you actually do not find the humanoid ?

local humanoid = character:FindFirstChild("Humanoid")
		if humanoid then
			healthLabel.Text = tostring(humanoid.Health)
			humanoid.HealthChanged:Connect(function(health)
				healthLabel.Text = tostring(health)
			end)
		end

try this

while not character:FindFirstChildWhichIsA("Humanoid", true) do wait() end
local humanoid = character:FindFirstChildWhichIsA("Humanoid", true)
if humanoid then
	healthLabel.Text = tostring(humanoid.Health)
	humanoid.HealthChanged:Connect(function(health)
		healthLabel.Text = tostring(health)
	end)
end
1 Like

Hmm, i tried it and it still does not change server side. I can see how that could be the issue tho, i will keep the change u said just to make sure, but yea the problem is still the same.

I dont know then, I tried making it and it works. This is server side

1 Like

If you’re willing to share that Gui, or at least showing us how it looks in explorer, that might help

oh, :sweat_smile: i realized that, it was my mistake. The hp was indeed fixed with your script.

but the level is still broken
i don’t mind sharing my gui if that could help. ive been stuck on this problem for like a week now

thank you again for fixing the hp!!

1 Like

i put it as an asset here it is: https://create.roblox.com/store/asset/18596811758/OverheadGuiScript

tell me when you have it so i can remove it from the asset store, i never did a creator store asset, so tell me if it works

It does not, you can download it from roblox as a file and share it here, that might be easier

Could you try it again, i realized that there is a button for enabling it on creator store and turned it on
its on now

Okay, it worked now, I got it.

1 Like

Okay, so the HP is working now. I dont really know how the level thing is supposed to work, but I also made the bar move.

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UpdateOverheadGuiVisibility = ReplicatedStorage.Remotes:WaitForChild("UpdateOverheadGuiVisibility")

-- Function to update the overhead GUI for a player's character
local function updateOverheadGui(character, player)
	--local player = Players:FindFirstChild(character.Name)
	--if not player then return end
	
	local overheadGui = character:FindFirstChild("OverheadGui")
	if not overheadGui then
		overheadGui = script.OverheadGui:Clone()
		overheadGui.Parent = character.Head
		overheadGui.Name = "OverheadGui"
	end
	
	local usernameLabel = overheadGui.Background:WaitForChild("Username")
	if usernameLabel then
		usernameLabel.Text = character.Name
	end
	
	local healthLabel = overheadGui.Background.OuterHealth:WaitForChild("Health")
	if healthLabel then
		local healthBar = overheadGui.Background.OuterHealth:WaitForChild("InnerHealth")
		
		if healthBar then		
			while not character:FindFirstChildWhichIsA("Humanoid") do wait() end
			local humanoid = character:FindFirstChildWhichIsA("Humanoid")
			if humanoid then
				healthLabel.Text = (tostring(humanoid.Health).." / "..tostring(humanoid.MaxHealth).." HP")
				healthBar.Size = UDim2.new((humanoid.Health / 100), 0, 1, 0)
				
				humanoid.Changed:Connect(function(property)
					if property == "Health" then
						healthLabel.Text = (tostring(math.floor(humanoid.Health * 10) / 10).." / "..tostring(humanoid.MaxHealth).." HP")
						healthBar.Size = UDim2.new((humanoid.Health / 100), 0, 1, 0)
					end
				end)
			end
		end
	end
	
	local levelLabel = overheadGui.Background.LevelBorder:WaitForChild("Level")
	if levelLabel then
		local playerLevel = player:GetAttribute("Level") or 1
		levelLabel.Text = tostring(playerLevel)
	end

	character.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
	character.Humanoid.HealthDisplayDistance = 0
	UpdateOverheadGuiVisibility:FireClient(player, overheadGui)
end

-- Bind the update function to player characters
local function onCharacterAdded(character, player)
	updateOverheadGui(character, player)
end

-- Bind the update function to existing players
for _, player in Players:GetPlayers() do
	player.CharacterAdded:Connect(onCharacterAdded)
	if player.Character then
		updateOverheadGui(player.Character)
	end
end

-- Bind the update function to new players
Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		onCharacterAdded(character, player)
	end)
end)
1 Like

thank you so much!, i will put this as solution, and i will probably just remove the level part of the ui if i cant fix it.

tysm again!

What do you need to fix about it ? Because I see it wants to set some player attribute as level.
local playerLevel = player:GetAttribute("Level") or 1
You need to change this for something else as your level, and it should work.

1 Like

alrighty ima try doing that and see how it goes!

Little update, i did as you said and it worked! the Gui is now completely functioning! i cannot express how grateful i am!

1 Like

No problem! Can’t wait to see what will you create.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.