Why does changing face not work after CharacterAdded?

No error in the output strangely. The problem: My character’s face doesn’t change as it should, in my setUpAvatar function. Any help is appreciated, thank you.

Please see the script below.

local DS = game:GetService("DataStoreService")
local cashInterval = 10  -- in minutes
local cashGiveValue = 2  -- in Cash

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	local cash = Instance.new("IntValue", leaderstats)
	cash.Name = "Cash"
	cash.Value = 0
	local startingCash = 0

	local scope = "Player_"..player.UserId
	local success, err = pcall(function()
		local playerStats = DS:GetDataStore("PlayerStats"):GetAsync("Player_" .. player.UserId)
		myCash = playerStats[1]
		print("Player stats for "..player.Name.." retrieved.")
	end)
	if success then
		cash.Value = myCash
		print("Player stats for "..player.Name.." established.")
	else
		cash.Value = startingCash
		print("Player stats for "..player.Name.." initiated.")
	end

	--  So the wallet is synced with the leaderstats value
	player.Backpack:WaitForChild("Wallet"):FindFirstChild("Handle"):WaitForChild("BillboardGui"):WaitForChild("CashAmount").Text = "$"..player.leaderstats.Cash.Value 

	--  Gives the player cash every certain period
	spawn(function()
	while wait(cashInterval*60) do
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + cashGiveValue
	end
	end)
	
	--  When the character loads
	player.CharacterAdded:Connect(function(character)
		setUpAvatar(character)
	end)


end)

game.Players.PlayerRemoving:Connect(function(player)
	print("Player ".. player.Name.. " is disconnecting.")
	pcall(function()
		DS:GetDataStore("PlayerStats"):SetAsync("Player_"..player.UserId, {player.leaderstats.Cash.Value})
		print("Player stats for "..player.Name.." saving success.")
	end)
end)

function setUpAvatar(character)
	delay(1, function()
	character:FindFirstChild("Head").face.Texture = "rbxassetid://34067417"
	--character:WaitForChild("Head"):WaitForChild("face"):Destroy()

--	local face = Instance.new("Decal", character.Head)
--	face.Texture = "rbxassetid://34067417"
	end)
end

First off, the setUpAvatar() function should be moved above the PlayerAdded() function, as it should be defined before trying to execute it. Try moving it above and then let me know if that does the fix.

Nope, that doesn’t work. It’s very strange.

After the CharacterAdded try player.CharacterAppearanceLoaded:Connect(function()

CharacterAppearanceLoaded fires once all the assets of the character is loaded, whilst CharacterAdded fires once a character is first found

Also try doing local function setUpAvatar(character) instead of just function setUpAvatar(character)

1 Like

The function is globally defined, so it’s fine as it is

Sloth, you should check the output for errors, if it says something like “face is not found”, then the issue is as Dandcx explained, you should use CharacterAppearanceLoaded