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:

01local player = game.Players.LocalPlayer
02local char = player.Character or player.CharacterAdded:Wait()
03local humanoid = char:FindFirstChild("Humanoid") or char:WaitForChild("Humanoid")
04local gui = THE PATH TO THE GUI YOU WANNA CHANGE THE ZINDEX OF
05local hp_required = THE CERTAIN HP TO TRIGGER THE CHANGE
06local zindex = THE ZINDEX  YOU WANT TO CHANGE IT TO
07local default_zindex = THE DEFAULT ZINDEX
08 
09 
10 
11humanoid:GetPropertyChangedSignal("Health"):Connect(function()
12 
13if humanoid.Health <= hp_required then
14gui.Zindex = zindex
15 
16else
17gui.Zindex = default_zindex
18end
19end)
Ad

Answer this question