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

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.

function grabplayers(plr)
	for i, player in ipairs (game.Players:GetPlayers()) do
	local Playername = player.Name
	
	if player.Character and plr.PlayerGui:FindFirstChild(Playername)== nil then
		local Billboard = Instance.new("BillboardGui",plr.PlayerGui)
		Billboard.Name = player.Name		
		Billboard.Adornee = player.Character.Head
		local clonehpthing = player.PlayerGui.ScreenGui.HP:Clone()
		clonehpthing.Parent = Billboard
		clonehpthing.Position = UDim2.new(0,0,0,0)
		clonehpthing.Size = UDim2.new(0,130,0,10)
		clonehpthing.Health:Destroy()
		clonehpthing.BorderSizePixel = 1
		print ("It finally works")
	end
	
	end
end

function distanceAppear(player)
	for i, plr in ipairs (game.Players:GetPlayers()) do
	local plrname = plr.Name
	if (plr.Character.Head.Position - player.Character.Torso.Position).magnitude > 30 then
		local plrGUI = player.PlayerGui[plrname]
		plrGUI.HP.Visible = false
	else
		local plrGUI = player.PlayerGui[plrname]
		plrGUI.HP.Visible = true
	end
	end
end

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.

1 answer

I changed some of the things for the BillboardGUI, and now it's working with a few bugs. ( Like DistanceAppear not working at all...)

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