Collection Service why this doesn't apply to all tagged part

local CollectionService = game:GetService("CollectionService")
local TaggedPart = CollectionService:GetTagged("Gems")

for _,TaggedPart in pairs(TaggedPart) do
	while true do
		wait()	
		TaggedPart.CFrame = TaggedPart.CFrame * CFrame.fromEulerAnglesXYZ(0,0.1,0)	
	end
end

Loops will go to the next iteration when the last iteration is finished which wont happen due to you making the script do a loop which never ends.
To make it cycle through all parts you need to coroutine the loop so it will run like so.

local CollectionService = game:GetService("CollectionService")
local TaggedPart = CollectionService:GetTagged("Gems")

for _,TaggedPart in pairs(TaggedPart) do
 local co = coroutine.wrap(function()
	while true do
		wait()	
		TaggedPart.CFrame = TaggedPart.CFrame * CFrame.fromEulerAnglesXYZ(0,0.1,0)	
	end
 end)
 co()
end
2 Likes

what is coroutine.wrap?
.
.
.
.
.
.

Its pretty much like creating a new script which wont affect the course of your original script.
There are 2 other functions which you could also use called spawn() and delay() but are not recommended due to how they work.

This might help, or simply do

local CollectionService = game:GetService("CollectionService")
local TaggedPart = CollectionService:GetTagged("Gems")

for _,TaggedPart in pairs(TaggedPart) do
 local co = coroutine.wrap(function()
	spawn(function() while true do
	       	wait()	
	    	TaggedPart.CFrame = TaggedPart.CFrame * CFrame.fromEulerAnglesXYZ(0,0.1,0)	
          end 
     end)
 end)
 co()
end