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

why wont my character face change?

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

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!

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()

2 comments

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

0

Open your output, are there any errors?

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