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

How do you change playermodel face on team change?

I'm currently working on an infection type game and I need help changing the face on the playermodel once you get switched to the infected team.

local faceId = "http://www.roblox.com/asset/?id=501885626"


game.Players.PlayerAdded:Connect(function(player)
	player.Changed:Connect(function(att)
		if att == "Team" then
			local char = player.Character or player.CharacterAdded:Wait()
			local head = player:WaitForChild("Head")
			local decal = head:WaitForChild("face")
			local desc = game.Players:CreateHumanoidModelFromUserId(player.UserId)
			local normalFace = desc.Face
			desc:Destroy()

			if player.Team == game.Teams.Infected then
				decal.Texture = faceId
			elseif player.Team == game.Teams.Survivors then
				decal.Texture = normalFace
			end
		end
	end)
end)

This is the code I have so far. Whenever I am testing and switch to the infected team it outputs Infinite yield possible on 'Players.jackcough62689:WaitForChild("Head")' Any help would be greatly appreciated.

1 answer

✓ Accepted answer

This is bc the code is constantly waiting for the head in the player, where there is none, so it will infinetely wait. Just switch out the player to char. Change line 8 to

local head = char:WaitForChild("Head")

6 comments

0

I did this and now I get the error Face is not a valid member of Model "Player"

0

What line is the error in?

0

Line 9

0

are u sure u added my code? I dont see a reason that the error should be there

0

I found a fix for it, thanks for the help.

0

Im curious what the problem was, can you explain where the error was int he script? and if my answer helped you solve your problem please accept it

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