Need help with health gui

how do i reset the bar back to full health after they respawn because right now it just shows 0

local HealthBar = script.Parent.Health.Bar
local healthPercent = HealthBar.Parent.PercentLabel
local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")

CoreGUIS.Health(healthPercent, HealthBar)

humanoid:GetPropertyChangedSignal("Health"):Connect(function()
	CoreGUIS.Health(healthPercent, HealthBar)
end)

game.Players.LocalPlayer.CharacterAdded:Connect(function(character)
	local humanoid = character:WaitForChild("Humanoid")
	
	CoreGUIS.Health(healthPercent, HealthBar)
end)
4 Likes

Put it under startercharacterscripts.

4 Likes

idk, it’s prob on somewhere like startergui, also what is CoreGUIS set to? (I don’t think that’s the problem, unless CoreGUIS is nil.) Yeah, you should rescript it and put it below StarterPlayer.StarterCharacterScripts.

1 Like

why would i put it in startercharacterscripts?

i tried that and it still doesnt reset the bar back to 100% after they respawn

1 Like

What if you try using game:GetService("Players").LocalPlayer.CharacterAdded:Connect() instead?
If it doesn’t work, try with if not game:IsLoaded() then game.Loaded:Wait()end to load the game first.

Another problem may be that the character is maybe already added when playing so CharacterAdded:Connect() will never fire. Just set character to local character=game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()

1 Like

I would first like to know were the script is located as this should not happen since you called when the character is added

1 Like

none of these are the case since using game:GetService(“Players”) is no different from game.Players. Also, you don’t really need to wait for the game to be loaded, you only really need the character. Lastly, CharacterAdded() will always run when a character respawns or spawns.

1 Like

the script is in startergui then i made one specifically for the player dying inside startercharacterscripts

1 Like

can you share that code? when the character dies, StaterCharacterScripts reset

1 Like

local CoreGUIS = require(game.ReplicatedStorage:WaitForChild("CoreGUIS"))
local HealthBar = game.Players.LocalPlayer.PlayerGui.Main.Health.Bar
local healthPercent = game.Players.LocalPlayer.PlayerGui.Main.Health.PercentLabel

game.Players.LocalPlayer.CharacterAdded:Connect(function(character)
	local humanoid = character:WaitForChild("Humanoid")

	humanoid.Died:Connect(function()
		CoreGUIS.Health(healthPercent, HealthBar)
	end)
end)

Yeah, I also knew that when I said so, just said bc I wasnt sure if it loaded on start.

You are waiting for the character AFTER the character loads, I think that’s the problem, but she’s running CoreGUIS.Health() on start so it doesn’t matter.

(in my opinion, it’s not a good way to script, but if it works, :person_shrugging:)

also i know that didnt help, I just didnt know what the issue was. the script should work

since this a local script, I suggest you just move it to StarterPlayerScripts instead especially if your script is calling when the player dies. Like I said earlier, when the player dies, all the scripts gets removed and reset

You mean StarterPlayerScripts, don’t you?

2 Likes

why is it not a good way to script it on start?

its my opinion, it doesnt matter how you script.

There should be a ResetOnSpawn property within your ScreenGui, simply ticking that should do the job.

nope i knew someone would say that lol i tried that and it didnt work

game.Players.LocalPlayer.CharacterAdded:Connect(function(character)
	local humanoid = character:WaitForChild("Humanoid")
	
	CoreGUIS.Health(100, HealthBar)
end)

i assume 100% is max so try this

percentlabel is the text thats wrong

use 100 on the healthbar then 1 of them has to be a value lol