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

Help getting player face decal?

I am wanting to randomly generate EVERY players face decal I have this script but I don't know how to locate all the players and change their face.

while wait(.7) do
	success = false
	pcall(function()
		id = math.random(1, 1000000000)
		if game.MarketplaceService:GetProductInfo(id).AssetTypeId==1 then success = true end
	end)
	if success then game.Players.ALLPLAYERS.Head.decal.Texture = "rbxassetid://"..id
		script.Parent.Text = "rbxassetid://"..id
		print ("rbxassetid://"..id)
		end
	end

On line 7 is where I need help. Thanks -gr3uh

1 answer

✓ Accepted answer
local FaceIds = { -- Just insert new Face Ids that you want to add into the random face's.
	5646474823,
	5303681402
}

--[[
Example of more
local FaceIds = { 
	5646474823,
	5303681402,
	5646474823,
	5303681402,
	5646474823,
	5303681402
}
]]
local rng = Random.new() -- Define the random variable so we can choose a random face
game.Players.PlayerAdded:Connect(function(player) -- Wait for player to be added
	player.CharacterAdded:Connect(function(character) -- Wait for players character. This will fire everytime a player dies.
		repeat wait() until character.Head ~= nil -- Wait for players head
		local head = character:WaitForChild("Head") -- Define head
		local face = head:WaitForChild("face") -- Define face
		local facetotake = FaceIds[rng:NextInteger(1,#FaceIds)] -- Choose a random face from the FaceIds table.
		face.Texture = "rbxassetid://".. facetotake -- Set players face to the random face.
	end)
end)
wait(15)
-- If you want to change faces after players are already joined, and not as they join, you can iterate through the children of players and do it that way
local function ChangeFaces() -- Create a function that we can just call later

	for i,v in pairs(game.Players:GetChildren()) do -- Iterate through all players, applying below code to each one.
		if v.Character then -- Make sure players character actually exists first
			local head = v.Character:WaitForChild("Head")
			local face = head:WaitForChild("face")
			local facetotake = FaceIds[rng:NextInteger(1,#FaceIds)]
			face.Texture = "rbxassetid://".. facetotake
		end
	end
end

-- Now on your line 7
if success then
	ChangeFaces()
end

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