Need help with CollectionService

I have a bunch of little characters with eyes, i want to make them all blink, i have done that using tween services but i would have to put a script into each and every eye, So im trying to use CollectionService to only use one script to make all of them blink, it almost works, but i want all of the eyes to blink at once, this script is only doing one eye at a time, heres the script

local CS = game:GetService("CollectionService")
local Eyes = "Eyes"
local EyesToMove = CS:GetTagged(Eyes)


while true do
	

for _, part in pairs(EyesToMove) do
	if part:IsA("BasePart") then
		
			local TweenService = game:GetService("TweenService")

			local tweenInfo = TweenInfo.new(0.5,Enum.EasingStyle.Exponential,Enum.EasingDirection.InOut, 0,true,0)
			local Settings = {Size = Vector3.new(0.153, 0, 0.116)}

			local Tween = TweenService:Create(part,tweenInfo,Settings)


			Tween:Play()
			wait(5)
	end
		
	end
end


Any help would be great.

That is because you yield for 5 seconds after you iterate just one eye.

I could understand your goal in two ways: you either want to have separate characters to blink with both eyes at once, or ALL of the existing eyes at once.

For the first case:
You could instead mark the head with a tag, find the eyes within it, and THEN do something like this:

while true do
    for _, List in EyePairs do
        for _, Eye in List do
            -- blink or smth
        end
    end

    task.wait(5)
end

Otherwise? It’s far simpler, actually you’re almost there:
image
Move the wait(5) to the while loop, so it takes 5 seconds between each blink, rather than individual eye blinking.

1 Like