HP BillboardGUI on players?
Well, recently, I've been trying to script something that involves putting a custom Health GUI on top of player's heads, that, and a bit of practice to learn how other GUI's work. Unless there's a better idea how to do this, i'll just do it in this manner because once the other players distance from the GUI, the GUI becomes invisible to them.
01 | function grabplayers(plr) |
02 | for i, player in ipairs (game.Players:GetPlayers()) do |
03 | local Playername = player.Name |
05 | if player.Character and plr.PlayerGui:FindFirstChild(Playername) = = nil then |
06 | local Billboard = Instance.new( "BillboardGui" ,plr.PlayerGui) |
07 | Billboard.Name = player.Name |
08 | Billboard.Adornee = player.Character.Head |
09 | local clonehpthing = player.PlayerGui.ScreenGui.HP:Clone() |
10 | clonehpthing.Parent = Billboard |
11 | clonehpthing.Position = UDim 2. new( 0 , 0 , 0 , 0 ) |
12 | clonehpthing.Size = UDim 2. new( 0 , 130 , 0 , 10 ) |
13 | clonehpthing.Health:Destroy() |
14 | clonehpthing.BorderSizePixel = 1 |
15 | print ( "It finally works" ) |
21 | function distanceAppear(player) |
22 | for i, plr in ipairs (game.Players:GetPlayers()) do |
23 | local plrname = plr.Name |
24 | if (plr.Character.Head.Position - player.Character.Torso.Position).magnitude > 30 then |
25 | local plrGUI = player.PlayerGui [ plrname ] |
26 | plrGUI.HP.Visible = false |
28 | local plrGUI = player.PlayerGui [ plrname ] |
29 | plrGUI.HP.Visible = true |
34 | game.Players.PlayerAdded:connect(grabplayers,distanceAppear) |
There's no errors in the output, but i think i wrote the script a bit wrong.
Also, if there's anything missing (Specifications, etc) i'll add more details (That is, if I can and it's relatable to the problem.)
Oh yeah, and the script is in Workspace
EDIT: The GUI is there (As demonstrated by typing game.Players.Username.PlayerGui.OtherUser.Name)
And the HP object is there too. However, when i write: game.Players.Username.PlayerGui.OtherUser.HP.Visible = true , nothing happens, and HP is clearly there, showing no errors in the command.