Billboardgui doesn't clone to player

hey my billboardgui never clones to the player

local g = {}
g.__index = g

local RankGui = script:WaitForChild('RankGui')

function g:Create(player, rank)
	local self = setmetatable({player = player, rank = rank}, g)
	
	local NewGui = RankGui:Clone()
	NewGui.Label.Text = rank
	NewGui.Parent = player.Character:FindFirstChild('Head')
	
	self.GUI = NewGui
	NewGui = nil
	
	return self
end


function g:Toggle(ena)
	self.GUI.Enabled = ena
end


function g:ChangeText(text)
	self.GUI.Label.Text = text
end



return g

local Players = game:GetService('Players')
local ReplicatedStorage = game:GetService('ReplicatedStorage')

local admin = require(ReplicatedStorage:WaitForChild('admin'))
local OverHeadModule = require(ReplicatedStorage:WaitForChild('OverHeadModule'))

local leaderstatsGroup = 'leaderstats'
Players.PlayerAdded:Connect (function(plr)
	
	if plr and plr.Character then
		local NewHeadGui = OverHeadModule:Create(plr, 'Guest')
		NewHeadGui:Toggle(true)
		
		
		local leaderstats = Instance.new('Model')
	    leaderstats.Name = leaderstatsGroup
	
		local Money = Instance.new('NumberValue')
		Money.Name = 'Money'
		Money.Value = 0
		
		Money.Parent = leaderstats
		
		leaderstats.Parent = plr
		
	end
	
end)

1 Like

I’m not sure about this, but if there’s no error, try setting the adornee property of the billboardgui to the head

........
NewGui.Adornee = player.Character:FindFirstChild('Head')
........
1 Like

nope, definitely doesn’t work maybe a module isn’t efficient enough?

Characters don’t load instantly as soon as the player joins, meaning that your script is running at a time plr.Character is nil, skipping the whole if block as a result. The module’s methods don’t effect this as they are simply never ran.

Instead you should be using the Player.CharacterAdded event, so you are assured that the character is present, at which point you can use the module as applicable:

Players.PlayerAdded:Connect (function(plr)
    -- The leaderstats are independent of the player's character, initiate them as
    local leaderstats = Instance.new('Model')
    leaderstats.Name = leaderstatsGroup
	
	local Money = Instance.new('NumberValue')
	Money.Name = 'Money'
	Money.Value = 0
		
	Money.Parent = leaderstats
	leaderstats.Parent = plr

    plr.CharacterAdded:Connect(function()
        -- Add new head GUI when the character has spawned
        local NewHeadGui = OverHeadModule:Create(plr, 'Guest')
		NewHeadGui:Toggle(true)
    end)
end)
1 Like