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

why wont my character face change?

Asked by 4 years ago

so i want the players head to change so it has no face but my code wont work

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(character)
        character.Head.face.Texture = "rbxassetid://167362548"
    end)
end)

i tried to use the Destroy function but it didnt do anything. im not sure what im doing wrong here

2 answers

Log in to vote
1
Answered by
Ghost40Z 118
4 years ago

You could make it so that it destroys the current face and replaces it with a new one. You do this by putting a ServerScript in ServerScriptServices and writing this code which I will now explain:

game.Player.PlayerAdded:Connect(function(player) --When player is added
    player.CharacterAdded:Connect(function() --When the character spawns
        local char = player.Character --the players character
        local head = char.Head --the characters head

        local faceid = "rbxassetid://000000000" --Here you need to swap the 0's with ur texture
        local currentface = head:GetChildren() --gets the children of the head
        for i,v in pairs(currentface) do --for loop runs through all objects in the head
            if v:IsA("Decal") and v.Name == "face" then --checks if a child is a decal named "face"
                v:Destroy() --if the decal is named "face" it destroys it.
            end
        end

        local newface = Instance.new("Decal") --makes a new decal
        newface.Name = "face" --names it face
        newface.Texture = faceid -- sets the texture
        newface.Parent = head --parents it to the head
    end)
end)

Hope this helped you understand it a bit more!

Ad
Log in to vote
0
Answered by 4 years ago

Probably multiple things but this question is very vague. Also open your output.

One thing it could be is that there could be a form of yielding before the event was assigned. If the player joins before the PlayerAdded was assigned, the function which is connected to the event won't be called with that player as an argument.

I suggest iterating for the current players in the server after assigning PlayerAdded. Sample:

local PlayerAdded = function()
    print('wow potato')
end

game.Players.PlayerAdded:Connect(PlayerAdded)
for _,a in pairs(game.Players:GetPlayers())do
    PlayerAdded(a)
end

Another thing I could think of is that the function in CharacterAdded could've ran too fast and errored while the character is still loading.

For this problem, I suggest waiting for the children using WaitForChild. Note: If you use WaitForChild with one argument would show a warn message, to get around this, insert a second argument of value math.huge. Sample:

character:WaitForChild('Head',math.huge):WaitForChild('face',10):Destroy()
0
i can confirm that the character loaded in as i added a line to make it print if the head and decal was found so i can confirm that. My problem is that i cant destroy or change the decal id mynam3with123 65 — 4y
0
Open your output, are there any errors? SoftlockedUnderZero 668 — 4y

Answer this question