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:
server sided:
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)
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
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.
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)
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.