Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you change playermodel face on team change?

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago

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")
0
I did this and now I get the error Face is not a valid member of Model "Player" jackcough62689 2 — 3y
0
What line is the error in? JustinWe12 723 — 3y
0
Line 9 jackcough62689 2 — 3y
0
are u sure u added my code? I dont see a reason that the error should be there JustinWe12 723 — 3y
View all comments (2 more)
0
I found a fix for it, thanks for the help. jackcough62689 2 — 3y
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 JustinWe12 723 — 3y
Ad

Answer this question