Hello, I designed a small place to be able to test some hair that I was making to practice, but as a result of this I have a small problem:
local block = script.Parent
local characterAccesory = script.Parent.Parent.Rig
local playerOnFloor = false
block.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
if humanoid and not playerOnFloor then
playerOnFloor = true
local character = humanoid.Parent
for _, accessory in ipairs(character:GetChildren()) do
if accessory:IsA("Accessory") and (string.find(accessory.Name:lower(), "hair") or string.find(accessory.Name:lower(), "Hair")) then
accessory:Destroy()
end
end
local accesorioRig = characterAccesory:FindFirstChildOfClass("Accessory")
if accesorioRig then
local accesorioNuevo = accesorioRig:Clone()
accesorioNuevo.Parent = character
else
warn("El accesorio no se encontrĂł en el Rig.")
end
end
end)
block.TouchEnded:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
if humanoid then
playerOnFloor = false
end
end)
Regardless of whether the script can be improved or not, my problem is that what I do is add my hair to the character and take out any other hair I have, but I do that by looking for an accessory that has the name “hair” or " Hair", however, not all hairs contain that type of name, is there any way I can remove everything that has to do with hairs or things on the head without having to do it this way and that it can also fail?, thank you.