Why won't the ui clone?

game.Players.PlayerAdded:Connect(function(Player)
	local function CharAdded()
		local OverHeadUi = game.ReplicatedStorage.Info:Clone()
		OverHeadUi.Parent = Player.Character.Head
		
		OverHeadUi.Main.Rank.Text = Player:GetRoleInGroup(5330486)
		OverHeadUi.Main.Username.Text = Player.Name
		print("End")
	end
	
	if Player.Character then
		CharAdded(Player.Character)
	end
	Player.CharacterAdded:Connect(CharAdded)
end)

It’s probably a little mistake but for some reason i can’t see it. It prints end so it does run through.

The issue with the code seems to be that you are passing an argument to the CharAdded function, but the function definition doesn’t include any arguments. To fix this, you can add a parameter to the function definition to accept the Character argument. Here’s the updated code:

game.Players.PlayerAdded:Connect(function(Player)
    local function CharAdded(Character)
        local OverHeadUi = game.ReplicatedStorage.Info:Clone()
        OverHeadUi.Parent = Character.Head
        
        OverHeadUi.Main.Rank.Text = Player:GetRoleInGroup(5330486)
        OverHeadUi.Main.Username.Text = Player.Name
        print("End")
    end
    
    if Player.Character then
        CharAdded(Player.Character)
    end
    Player.CharacterAdded:Connect(CharAdded)
end)

This should now properly add the OverHeadUi to the player’s head when they spawn.

Before parenting the UI, you need to set the Adornee property. Set the property to the character’s head.

for some reason the ui doesn’t even clone at all.

It’s because you didn’t assign character as an argument to the function now that I think about it.

local GamepassIconHoveringId
game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local OverHeadUi = ReplicatedStorage:WaitForChild("Info"):Clone()
		OverHeadUi.Adornee = Character:WaitForChild("Head")
		OverHeadUi.Parent = Character:WaitForChild("Head")

		OverHeadUi.Main.Rank.Text = Player:GetRoleInGroup(5330486)
		OverHeadUi.Main.Username.Text = Player.Name
		print("End")
	end)
end)

But i did

Okay, in that case, make sure the ui itself is actually visible. To do this, parent it into a part in studio and set the Adornee.

Player.CharacterAdded:Connect(function(Character)
Player.CharacterAppearanceLoaded:Wait()
local OverHeadUi = ReplicatedStorage:WaitForChild(“Info”):Clone()
OverHeadUi.Adornee = Character:WaitForChild(“Head”)
OverHeadUi.Parent = Character:WaitForChild(“Head”)

	OverHeadUi.Main.Rank.Text = Player:GetRoleInGroup(5330486)
	OverHeadUi.Main.Importance.Text = "%%%%"
	OverHeadUi.Main.Username.Text = Player.Name
	print("End")
end)

Basically the character’s children wasn’t fully loaded in so i added CharacterApperanceLoaded:Wait()

That shouldn’t happen usually… unless it’s a client script.

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