Mask remove error?

So I have this mask remove script (inside of the tool) and it is giving me an error the nil value. Any help?

local re = script.Parent.RemoveMask

re.OnServerEvent:Connect(function(player)
	local character = player.Character
			wait(1)
			local d = character:GetChildren()
			for i=1, #d do
				if (d[i].className == "Accessory") and (d[i].Name == "Hair") then
					d[i].Handle.Transparency = 0
					if (#d[i].Handle:GetChildren()) > 0 then 
					player.Character:FindFirstChild("Balaclava"):Destroy()
				local dog = character.BlackMask or player.Backpack.BlackMask
				character.Head.Hidden.Enabled = false
				character.Head.Title.Enabled = true
				dog.Handle.Transparency = 0
				end
				else
				if (d[i].className == "Accessory") and (d[i].Name == "Hair") and (d[i].Handle:FindFirstChild("Prop")) then
				local d = character:GetChildren()
				for i=1, #d do
				if (d[i].className == "Accessory") and (d[i].Name == "Hair") then
				d[i].Handle.Transparency = 0
				local f = d[i].Handle:GetChildren()
			        for i=1, #f do
				if f[i].Name == "Prop" then
					f[i].Transparency = 0
				end
			end
				end
				end
				end
				end
player.Character:FindFirstChild("Balaclava"):Destroy() --- Where it errors
				local dog = character.BlackMask or player.Backpack.BlackMask
				character.Head.Hidden.Enabled = false
				character.Head.Title.Enabled = true
				dog.Handle.Transparency = 0
				end
			end)
1 Like

some players, cant have Balaclva on their character or is a custom character?

Custom character. With names any everything.

you should change that to

				for i, v in pairs(d) do
				if (d[v].className == "Accessory") and (d[v].Name == "Hair") then
				d[v].Handle.Transparency = 0
				local f = d[v].Handle:GetChildren()
			        for i, v in pairs(f) do
				if f[v].Name == "Prop" then
					f[v].Transparency = 0
				end
			end

Try to check that it exists first, and that the name is the same

hat = player.Character:FindFirstChild("Balaclava")
if hat then
    hat:Destroy()
end

or check for attachments

for _, hat in pairs(player.Character:GetChildren()) do
    if hat:IsA('Accountrement') then
        hat:Destroy()
    end
end
-- Note this will delete all hats & accessories. A whitelist or a name check is probably also necessary if there are multiple hats

i will go to roblox studio to rewrite all

can u give me the character model?

Its no different character models, its just a naming system with hairs and packages.

im very close to repair it!, note if u want some changes say

that “Proop” what is? a bool value? or a brick? or what?

Its a seperate part in the hair handle.

1 Like

Can you tell us where exactly the error is occurring?

I did in the code. Character30

It’s returning nil because the object Balaclava does not exist.
To prevent the error, simply check first if the object exists, if so, then remove it.

if player.Character:FindFirstChild("Balaclava") then
	player.Character:FindFirstChild("Balaclava"):Destroy() --- Where it supposedly errorred
end
1 Like