Hey, I’ve been trying to add blinking to my NPC. But it just doesn’t work, there used to be an error saying attempt to index nil with “Closed” but since I added the “if face then” it’s gone. But it still doesn’t work, could anyone check it out and tell me what is wrong?
local faceTable = {}
for i,v in pairs(game.ReplicatedStorage:WaitForChild("Faces"):GetChildren()) do
table.insert(faceTable,v)
end
local face = faceTable[math.random(1,#hairTable)]
local mobFace = mob:WaitForChild("Head"):WaitForChild("Decal")
if mobFace and face then
coroutine.wrap(function()
while true do
mobFace.Texture = face:WaitForChild("Closed").Texture
wait(0.5)
mobFace.Texture = face:WaitForChild("Open").Texture
end
end)()
end
As I can see you’re trying to find all faces inside of Replicated Storage, but isnt that easier to just find them with WaitForChild?
Thats blinking script that i using in my game:
local Face = script.Parent
local Closed = Face:GetAttribute("Closed")
local Open = Face:GetAttribute("Open")
local Wtick = Face:GetAttribute("Tick")
if Face then
while true do
local randomV = math.random(15,50) / 10
wait(randomV)
Face.Texture = Closed
wait(Wtick)
Face.Texture = Open
end
end
I added 3 Attributes: Closed eyes texture, Open eyes texture and delay between opening and closing eyes
Thats seems like easiest way to do it in my opinion
'attempt to index nil with “Closed”' means that the face doesn’t exist
My first questions here then are:
Are there faces in the face folder?
If the answer to that is yes, does the number of items in the hair table match the number of items in the face table
If the answer to that is no, that might be your issue
third, add a wait(0.05) between the open texture and the end of the while true do loop, as the textures might be changing so fast that it LOOKS like nothing is happening