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

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

Asked by 6 years ago

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

Log in to vote
3
Answered by 6 years ago
Edited 6 years ago

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.

0
You could also just replace the already existing face decal so there aren't 2 of them overlapping each other. ShinyGriffin 129 — 6y
0
The old one is automatically destroyed when the character is destroyed, there is no reason not to create the face from inside CharacterAdded. SummerEquinox 643 — 6y
Ad

Answer this question