CharacterAdded not firing because of StarterCharacter

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)

- No errors or prints in the Output

Screen Shot 2022-10-16 at 6.02.42 PM

Screen Shot 2022-10-16 at 6.02.23 PM

1 Like

Move your script to ServerScriptService.

Do you mean ServerScriptService or ServerStorage? ‘ServerScriptStorage’ does not exist :joy:

FYI scripts can run in both places, it doesn’t matter

Bruh, I keep doing this. Fixed.

1 Like

Have you tried doing workspace:ChildAdded and then check if the child is a player’s character?

Try putting the Health script to StarterCharacterScripts.

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.

Hope this helps.

This would not work. It would only appear to the client. His script is fine, it just needs to be moved to ServerScriptService.

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.

My bad!