BillBoardGui on the player's head

I’m having a problem where I want to clone a billboard gui on top of the player’s head. The issue I’m facing is that when the player joins the game sometimes the billboard Parent isn’t set but if he resets they will have the board on top of them.(The billboard is cloning just fine the issue is setting it’s parent). Why is this happening? Does the character is loading too fast for the clone’s parent to be set?

game.Players.PlayerAdded:Connect(function(plr)
     plr.CharacterAdded:Connect(function(char)
		local head = char:WaitForChild("Head")
		local cloneBill = playerBillGui:Clone()
		cloneBill.Parent = head
	end)
end)
2 Likes

Try to use repeat until loop which will repeat an argument until requirement has been meet. For an argument, we will include that we need to parent BillboardGUI to character’s head and the requirement will be alike “if character’s head has BillboardGUI children”. Also you can use if then statement to check if your head does have BillboardGUI.

So lets implement this to your code:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local head = char:WaitForChild("Head")
		local cloneBill = playerBillGui:Clone()
		
		repeat
			cloneBill.Parent = head
		until head:FindFirstChildOfClass("BillboardGui")
		
		if head:FindFirstChild("HereGoesNameOfBillboardGUI") then
			print("Added BillboardGUI to "..plr.Name.."!")
		else
			print("Couldn't add BillboardGUI to "..plr.Name..". *sad trombone*")
		end
	end)
end)

In line 10, which is if head:FindFirstChild("HereGoesNameOfBillboardGUI") then include a name of your BillboardGUI as it’s to make sure that is actually in character’s head.

1 Like

That works! Thanks for helping me :slight_smile:

2 Likes

No problem, ask any questions if you interested in this code! :smiley:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.