Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago

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)
Ad

Answer this question