I have these methods in a module, and when I call each of them, only the bilboarg gui of the 1st one doesn’t get deleted, the other 2 dissapear, any issues to how i have fix this?
function module:LoadTop1Character(UserId, Podiums, Players)
local succes, err = pcall(function()
Podiums.Top_1.PlayerModel.Humanoid:ApplyDescription(Players:GetHumanoidDescriptionFromUserId(UserId))
end)
Podiums.Top_1.PlayerModel.Head.BillboardGui.TextLabel.Text = Players:GetNameFromUserIdAsync(UserId)
end
function module:LoadTop2Character(UserId, Podiums, Players)
local succes, err = pcall(function()
Podiums.Top_2.PlayerModel.Humanoid:ApplyDescription(Players:GetHumanoidDescriptionFromUserId(UserId))
end)
end
function module:LoadTop3Character(UserId, Podiums, Players)
local succes, err = pcall(function()
Podiums.Top_3.PlayerModel.Humanoid:ApplyDescription(Players:GetHumanoidDescriptionFromUserId(UserId))
end)
Podiums.Top_3.PlayerModel.Head.BillboardGui.TextLabel.Text = Players:GetNameFromUserIdAsync(UserId)
end
Seems like this is intended behavior as body parts gets completely replaced if it doesn’t match the new description. I used this script to test the behavior:
local function onDescendantAdded(descendant: Instance): ()
print(`+ {descendant:GetFullName()}`)
end
local function onDescendantRemoving(descendant: Instance): ()
warn(`- {descendant:GetFullName()}`)
end
script.Parent.DescendantAdded:Connect(onDescendantAdded)
script.Parent.DescendantRemoving:Connect(onDescendantRemoving)
for _: number, descendant: Instance in script.Parent:GetDescendants() do
task.spawn(onDescendantAdded, descendant)
end
Anyways, parent the BillboardGui to the model and set the Adornee property to the head instead. After applying your HumanoidDescription, set the Adornee property again since the old one might be destroyed:
-- example
local succes, err = pcall(function()
Podiums.Top_1.PlayerModel.Humanoid:ApplyDescription(Players:GetHumanoidDescriptionFromUserId(UserId))
end)
local billboardGui = Podiums.Top_1.PlayerModel:FindFirstChildOfClass("BillboardGui")
local head = Podiums.Top_1.PlayerModel:FindFirstChild("Head")
billboardGui.Adornee = head
I get this error, the first stand loads successfully the other 2 not so much.
ReplicatedStorage.Leaderboard Handler.Player Model Handler:22: attempt to index nil with 'Adornee'
function module:LoadTop2Character(UserId, Podiums, Players)
local succes, err = pcall(function()
Podiums.Top_2.PlayerModel.Humanoid:ApplyDescription(Players:GetHumanoidDescriptionFromUserId(UserId))
end)
local billboardGui = Podiums.Top_2.PlayerModel.Head:FindFirstChildOfClass("BillboardGui")
local head = Podiums.Top_2.PlayerModel:FindFirstChild("Head")
billboardGui.Adornee = head
end