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