Script not working

function onDeath()
	local rbxlink = "rbxassetid://" -- Do not change this, or the script will no longer work
	local facetexture = "1367341140" -- Change the value in the brackets if you want to use a different face id, do not remove the brackets
	local head = script.Parent:FindFirstChild("Head")
	if head ~= nil then
		for i,v in pairs(head:GetChildren()) do
			if v:IsA("Decal") then
				pcall(function()
					local Decal = game.InsertService:LoadAsset(facetexture):GetChildren()[1]
					Decal.Parent = head
				end)	
				v.Texture = rbxlink..facetexture
			end
		end
	end 
end

script.Parent.Humanoid.Died:Connect(onDeath)``

Does anyone know why this script isnt working? its a script placed in “StarterCharacterScripts” and its goal is to change the players face on death

Can you show me the output(If it have error)

you forgot the “rbxassetid://”

local Decal = game.InsertService:LoadAsset(rbxlink..facetexture):GetChildren()[1]

oh ill try that out . i thought it was supposed to be like that but i should’ve tried that.

here it is;


i didnt see anything in the output mentioning the script at all but i might just be blind

hmmm, nothing is about the face. I think you need to use Kaid3n22 script:local Decal = game.InsertService:LoadAsset(rbxlink…facetexture):GetChildren()[1]

ok thanks im testing that out now.

The line using InsertService is useless if you’re not gonna destroy the old face, you can just change the old face’s texture. You can delete the whole pcall function.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

character.Humanoid.Died:Connect(function()
	local rbxlink = "rbxassetid://" -- Do not change this, or the script will no longer work
	local facetexture = "1367341140" -- Change the value in the brackets if you want to use a different face id, do not remove the brackets
	local head = script.Parent:FindFirstChild("Head")
	if head ~= nil then
		for i,v in pairs(head:GetChildren()) do
			if v:IsA("Decal") then	
				v.Texture = rbxlink..facetexture
			end
		end
	end 
end)

This worked for me inside starter character scripts(its a LocalScript but it should work with a Server Script also). Try using prints() and see if the function is actually firing.

i used your script but it didnt change the face at all. here is the current script;
function onDeath()
local rbxlink = “rbxassetid://” – Do not change this, or the script will no longer work
local facetexture = “rbxassetid://1367341140” – Change the value in the brackets if you want to use a different face id, do not remove the brackets
local head = script.Parent:FindFirstChild(“Head”)
if head ~= nil then
for i,v in pairs(head:GetChildren()) do
if v:IsA(“Decal”) then
pcall(function()
local Decal = game.InsertService:LoadAsset(rbxassetid://1367341140):GetChildren()[1]
Decal.Parent = head
end)
v.Texture = rbxlink…facetexture
end
end
end
end

script.Parent.Humanoid.Died:Connect(onDeath)

This is needlessly complicated, here is essentially the same thing rewritten.

script.Parent.Humanoid.Died:Connect(function()
    local face = script.Parent:FindFirstChild("Head"):FindFirstChildOfClass("Decal")
    if face then
        face.Texture = "YOUR_ASSET_URL_HERE" -- rbxassetid://########
    end
end)

You forgot the quotation marks around the assetid.

tahnks. i tried it with a server script and it didnt work so im trying it with a local script now.

oh im dumb give me one second im replying to 2 other people

this worked. thank you.
@LowPolys im trying out yours now. unfortunatley i have already found a solution.

Doing this on the client will only appear on your screen and not others. This is due to something called “FilteringEnabled”. If you want it to appear on every players screen you’ll want to do it in a Server Script.

Put this script inside “ServerScriptService”


game.Players.PlayerAdded:Connect(function(player)--Fires when a player joins the game
	player.CharacterAdded:Connect(function(character)--Waits for the player's character to load in
		local humanoid = character:WaitForChild("Humanoid")--Waiting for the humanoid to load in
		humanoid.Died:Connect(function()
			local head = character:FindFirstChild("Head")
			if head then
				for i,v in pairs(head:GetChildren()) do--Replacing all faces with the dead face
					if v:IsA("Decal") then	
						v.Texture = "rbxassetid://1367341140"
					end
				end
			end 
		end)
	end)
end)

FilteringEnabled is super important so I recommend you learn more about it. You have https://scriptinghelpers.org/questions/47956/what-is-filtering-enabled#:~:text=Filtering%20Enabled%20is%20a%20form,make%20changes%20to%20the%20game. and other threads.

oh yeah. ill have to test that script later with a friend. and ill look at the fe post. thanks

1 Like