Instance.new isn't creating object when player joins

A continuation of this thread, now that my problem’s a bit different.

I have a script set up to make a BillboardGui and parent it to the player’s head when they join. However, it just doesn’t create either at all. I’ve looked at similar “Instance.new isn’t working” threads with this same exact issue, and I appear to be doing everything right…

I have no scripts that reparent or delete this BillboardGui, and this script used to work just fine!
The Player and Character being added also aren’t the issue, I’ve already done print tests for these.

game.Players.PlayerAdded:Connect(function(plr)


	plr.CharacterAdded:Connect(function(char)


		local nameGui = Instance.new("BillboardGui")

		nameGui.StudsOffset = Vector3.new(0, 3, 0)

		nameGui.Size = UDim2.new(0, 200, 0, 50)

		nameGui.Name = "BioGui"
		nameGui.Parent = char.Head

		nameGui.MaxDistance = 100


		local nameLabel = Instance.new("TextLabel")

		nameLabel.Text = "-"

		nameLabel.TextScaled = true
		
		nameLabel.TextWrapped = true

		nameLabel.Size = UDim2.new(.5, 100, 0, 25)

		nameLabel.BackgroundTransparency = 1

		nameLabel.TextColor3 = Color3.fromRGB(255, 255, 255)

		nameLabel.Font = 4

		nameLabel.TextStrokeColor3 = Color3.new(0, 0, 0)

		nameLabel.TextStrokeTransparency = .5

		nameLabel.Name = "BioLabel"
		nameLabel.Parent = nameGui

	end)

end)
1 Like

im almost 100% certain instance.new isnt the issue. Because you would get an error when trying to set its name or parent since you cant set the parent of a nil value.

Can you change argument char to other thing?

Try this:

game.Players.PlayerAdded:Connect(function(plr)
	
	local function createHeader(char)
		local nameGui = Instance.new("BillboardGui")

		nameGui.StudsOffset = Vector3.new(0, 3, 0)

		nameGui.Size = UDim2.new(0, 200, 0, 50)

		nameGui.Name = "BioGui"
		nameGui.Parent = char.Head

		nameGui.MaxDistance = 100


		local nameLabel = Instance.new("TextLabel")

		nameLabel.Text = "-"

		nameLabel.TextScaled = true

		nameLabel.TextWrapped = true

		nameLabel.Size = UDim2.new(.5, 100, 0, 25)

		nameLabel.BackgroundTransparency = 1

		nameLabel.TextColor3 = Color3.fromRGB(255, 255, 255)

		nameLabel.Font = 4

		nameLabel.TextStrokeColor3 = Color3.new(0, 0, 0)

		nameLabel.TextStrokeTransparency = .5

		nameLabel.Name = "BioLabel"
		nameLabel.Parent = nameGui
	end
	
	repeat wait() until plr.Charater and plr.Character:FindFirstChild("Head")
	
	createHeader(plr.Character)
	
	plr.CharacterAdded:Connect(function(char)

		createHeader(char)
		

	end)

end)

Player.CharacterAdded doesn’t fire when player joins

1 Like

BillboardGui.Adornee = Instance
You’ve forgotten to assign the billboard’s ‘Adornee’ property (which specifies what physical instance the interface should be cast from). This property should default to the billboard’s parent however.

https://developer.roblox.com/en-us/api-reference/property/BillboardGui/Adornee

local Game = game
local Players = Game:GetService("Players")

local function OnPlayerAdded(Player)
	local function OnCharacterAdded(Character)
		if not Player:HasAppearanceLoaded() then
			Player.CharacterAppearanceLoaded:Wait()
		end

		local Head = Character:WaitForChild("Head")

		local BillboardGui = Instance.new("BillboardGui")
		BillboardGui.Adornee = Head
		BillboardGui.Parent = Head
	end

	Player.CharacterAdded:Connect(OnCharacterAdded)
end

Players.PlayerAdded:Connect(OnPlayerAdded)

This is working on my end.

image

3 Likes

This made it work! Thanks a ton.

For my own reference, revised version of the script:

local Game = game
local Players = Game:GetService("Players")

local function OnPlayerAdded(Player)
	local function OnCharacterAdded(Character)
		if not Player:HasAppearanceLoaded() then
			Player.CharacterAppearanceLoaded:Wait()
		end

		local Head = Character:WaitForChild("Head")

		local nameGui = Instance.new("BillboardGui")
		nameGui.StudsOffset = Vector3.new(0, 3, 0)
		nameGui.Size = UDim2.new(0, 200, 0, 50)
		nameGui.Name = "BioGui"
		nameGui.Adornee = Head
		nameGui.Parent = Head
		nameGui.MaxDistance = 100
		
		local nameLabel = Instance.new("TextLabel")
		nameLabel.Text = "-"
		nameLabel.TextScaled = true
		nameLabel.TextWrapped = true
		nameLabel.Size = UDim2.new(.5, 100, 0, 25)
		nameLabel.BackgroundTransparency = 1
		nameLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
		nameLabel.Font = 4
		nameLabel.TextStrokeColor3 = Color3.new(0, 0, 0)
		nameLabel.TextStrokeTransparency = .5
		nameLabel.Name = "BioLabel"
		nameLabel.Parent = nameGui
	end

	Player.CharacterAdded:Connect(OnCharacterAdded)
end

Players.PlayerAdded:Connect(OnPlayerAdded)