Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is this CharacterAdded script only working half of the time?

Hello, I've made this simple script to force-change the player's face when they join and respawn. For some reason, it arbitrarily doesn't work about every 2/10 tests. Meaning, the player's face doesn't change on join/respawn.

Any possible reason for this?

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		repeat wait() until Player.Character
		
		Character:WaitForChild('Head').face.Texture = "rbxassetid://405704912"
	end)
end)

1 answer

Server Script

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		repeat wait() until workspace:FindFirstChild(Player.Name) ~= nil
		Character:WaitForChild("Head").face.Texture = "rbxassetid://405704912"
		local Humanoid = Character:WaitForChild("Humanoid")
		Humanoid.Died:Connect(function()
			wait(3)
			Player:LoadCharacter()
		end)
	end)
end)

Firstly, the repeat loop should wait for the player's character to be in the workspace, since there is a delay between the character instance and its parenting.

Secondly, to make sure the face resets, you can use the Humanoid.Died Event and then Load the Character before the default approx. 5 second delay ends.

Doing this will cause the CharacterAdded Event to occur again and force the face change.

This discussion is preserved as it was. New answers, comments, and votes are closed.