How do I change player Transparency?

I’m attempting to make my player’s head be at .8 transparency, but this isn’t working out. It returns 0 errors. I’m sure it’s something very simple, but i don’t know what I’m doing wrong. thanks.

game.Players.PlayerAdded:connect(function(player)
player:WaitForChild("Character").Head.Transparency = .8
end)
1 Like

It’s because you’re calling Player:WaitForChild(“Character”)
Character isn’t a descendant of Player, it’s a property.
Instead, do

game.Players.PlayerAdded:connect(function(player)
     local Character = player.Character or player.CharacterAdded:wait()
     Character.Head.Transparency = .8
end)
4 Likes

The variable “player” is the Player Object. You’re looking and waiting for a child named “Character” in the Player Object.

What you could do instead is assign the character (or yield for the CharacterAdded event) to a variable, like so:

game.Players.PlayerAdded:connect(function(player)
    local char = player.Character or player.CharacterAdded:wait()
    --some more code!!!
end)
1 Like

@Firefaul & @Locard thank you! you both were helpful. :slight_smile:

2 Likes

No problem, happy to help!

2 Likes

Those would only work once to note.

game:GetService("Players").PlayerAdded:Connect(function (player)
 player.CharacterAdded:Connect(function (character)
  character:WaitForChild("Head").Transparency = 0.8
 end)
end)

This would set the character’s head transparency per time they respawn.

2 Likes

Just to complicate things further, here’s code that handles the extremely small possibility that the player leaves during a spawn and the head didn’t load yet, thus avoiding an infinite yield waiting for the head:

game:GetService("Players").PlayerAdded:Connect(function (player)
	player.CharacterAdded:Connect(function (character)
		local head = character:WaitForChild("Head", 5)
		if (head) then
			head.Transparency = 0.8
		end
	end)
end)
5 Likes

Thank you!