Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make a gui zindex change when your hp reaches a certain point?

so me and my friend are making a game and i'm working on a health bar. and I dont know how to change the zindex of a gui specifically when your hp reaches a certain point. Thanks for looking at this post

1 answer

You can do this with a local script:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:FindFirstChild("Humanoid") or char:WaitForChild("Humanoid")
local gui = THE PATH TO THE GUI YOU WANNA CHANGE THE ZINDEX OF
local hp_required = THE CERTAIN HP TO TRIGGER THE CHANGE
local zindex = THE ZINDEX  YOU WANT TO CHANGE IT TO
local default_zindex = THE DEFAULT ZINDEX



humanoid:GetPropertyChangedSignal("Health"):Connect(function()

if humanoid.Health <= hp_required then
gui.Zindex = zindex

else
gui.Zindex = default_zindex
end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.