I am currently trying to add an Overhead Ui into my Roblox Game, the problem is that every time the Player dies the Overhead Ui disappears due to CharacterAdded not working. I am unsure if this is because of the StarterCharacter or a different issue.
local function UpdateHealth(Humanoid, Bar)
Bar.Size = UDim2.new((Humanoid.Health / Humanoid.MaxHealth),0,1,0)
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(Character)
print("E")
Character.PrimaryPart.CFrame = workspace.Spawns[player:WaitForChild("SpawnLocation").Value].CFrame
local OverheadUi = game.ReplicatedStorage.UserInterface.OverheadUi:Clone()
OverheadUi.Parent = Character.Head
OverheadUi.DisplayName.Text = player:WaitForChild("FirstName").Value.." "..player:WaitForChild("LastName").Value
OverheadUi.Username.Text = "(@"..player.Name..")"
UpdateHealth(Character.Humanoid, OverheadUi.HealthBar.Frame)
Character.Humanoid.HealthChanged:Connect(function()
UpdateHealth(Character.Humanoid, OverheadUi.HealthBar.Frame)
end)
end)
end)
your script is inside starterplayerscripts making it only load once the player has loaded
the playeradded function is called when a player is about to load, move your script it serverscriptservice or remove the playeradded function and set the player to script.Parent.Parent
Health should be a LocalScript in StarterCharacterScripts.
If I’ve interpreted your code right, it might be easier to make the GUI ResetOnSpawn property false, and change the properties of the bar when the humanoid’s health changes, using :GetPropertyChangedSignal().
local function update_health()
local function main(plyr)
while not plyr.Character and not plyr.Character:FindFirstChild("Humanoid") do
wait()
end
plyr.Character:FindFirstChild("Humanoid"):GetPropertyChangedSignal("Health"):Connect(function()
-- your GUI code here
end)
end
game:GetService("Players").PlayerAdded:Connect(main)
If I’ve interpreted what you’re going for, let me know.
Ah, I figured that they were going to suspend health regen for the humanoids (hence the naming of the script!) and then handle updating GUIs client-side.