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

How to make all players spawn with a specific face (decal + head)?

Self explanatory, but I am trying to make a script in where when a player spawns, a decal is placed on their "face".

This is the code I've done so far.

faceid = 2554833537
face = game.player.Character.Head.Insert.new("Decal")

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		if character:WaitForChild("Head") then 
			character.Head.face = "http://www.roblox.com/asset/?id="..faceid
			
		end
	end)
end)

What would I need to add and fix?

Thanks in advance

1 answer

You seem to lack an understanding of how to create new objects in Roblox Lua.

This is done by using:

local newObjectOfClass = Instance.new("Class")

or in your case,

local face = Instance.new("Decal")

Now, onwards from that - in the code that you have provided you create a single instance of your desired decal, not one for each player. To amend this, you need to create the new instance from inside of the specified player's code subsidy.

Consider the following:

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local face = Instance.new("Decal")
	end)
end)

This way, we will create a new instance of face for each character that is added.

After this, all that's left is to parent the new face instance to the designated character, and apply the desired ID.

local faceInstanceID = "Desired Decal ID"

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local faceInstance = Instance.new("Decal")
		faceInstance.Texture = faceInstanceID
		faceInstance.Parent = Character.Head
	end)
end)

If you have any further questions, don't hesitate to ask.

2 comments

0

You could also just replace the already existing face decal so there aren't 2 of them overlapping each other.

0

The old one is automatically destroyed when the character is destroyed, there is no reason not to create the face from inside CharacterAdded.

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