Help with making a health script

I need help making a script for a custom health Gui I made
so basically when the player takes damage one of the hearts goes transparent and then they lose the second heart they die, so each heart is 50 health all together that 100 health. Any articles or videos would be greatly appreciated

1 Like

I would have a RemoteEvent fired from the server (including which heart to remove) to a local script, which then sets the correct label’s transparency to 1.

There are likely more efficient ways but this should work.

1 Like

Thanks so much I was thinking to use if statements but I was just stuck then you remined me about remote event, good looking

Do you still need any help with this?


What I’d do is add a listener for the HealthChanged event from the Humanoid instance. Then from there, use the parameter provided in said event to fire the player’s new health to the client. Then, get the health percentage by dividing the player’s current health to their max health.

local numHearts = 2

function onHealthChanged(newHealth)
	local hpPercent = newHealth / humanoid.MaxHealth--Get the player's health percentage
	local heartsLeft = math.ceil(hpPercent * numHearts) -- Multiply the maximum number of hearts by the 		percentage and use math.ceil to get the int >= the multiplied value to get the number of hearts remaining.
	remoteEvent:FireClient(player, heartsLeft) --Fire to the damaged player's client.


Then after it’s fired to the client, just do a for i loop to determine how many hearts should be filled. :slight_smile:

1 Like

No i dont but i have a question how did you learn how to script i have bin watching the dev king hes awesome but i want to be able to have and idead and just make it did you sue roblox developer api?

Thanks a lot question how did you learn how to code so well

1 Like

There are many ways to learn. From reading the developer hub’s documentation and tutorials to even just reading through free models, you can learn a lot!
If my code and response has helped you with your question, please mark it as solution. Thank you! :grinning:

I learnt to script using AlvinBlox and some other YouTubers.