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)
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
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