:SetPrimaryPartCFrame() does not work on tagged parts using CollectionService

So I tried making my future coming obby game tidier by using CollectionService so I won’t have to put a script on each object and I’m having a problem with making the spinners spin. I had no errors, here’s the code:

local CollectionService = game:GetService("CollectionService")
local TaggedParts = CollectionService:GetTagged("Spinner2")

for _, TaggedPart in pairs(TaggedParts) do
	while true do
		wait()
		TaggedPart:SetPrimaryPartCFrame(TaggedPart.PrimaryPart.CFrame * CFrame.Angles(0, 0, TaggedPart.Speed.Value))
	end
end

Any help is appreciated!
I added tags using a plugin, which worked for other objects, but not the spinners.

1 Like

I’m not fully familiar with the Collection Service, however you could try:

local CollectionService = game:GetService("CollectionService")
local TaggedParts = CollectionService:GetTagged("Spinner2")

for _, TaggedPart in pairs(TaggedParts) do
	while true do
		wait()
		TaggedPart:SetPrimaryPartCFrame(TaggedPart.PrimaryPart.CFrame * CFrame.fromEulerAnglesXYZ(0,0,TaggedPart.Speed.Value))
	end
end

I’m not 100% sure on this but i have used the code to rotate objects before.

while true do
    for _, TaggedPart in ipairs(TaggedParts) do
        TaggedPart:SetPrimaryPartCFrame(TaggedPart.PrimaryPart.CFrame * CFrame.Angles(0, 0, TaggedPart.Speed.Value))
    end
    task.wait()
end

Problem is that the while loop prevents the next cycle of the for loop since its ran on a single thread, just switch it around like this and it will work

2 Likes

You’re yielding forever with the while loop, you could run it on another thread, or use TweenService/RunService to execute the animation.

On the other hand :SetPrimaryPartCFame() is deprecated, instead use :PivotTo() which directly doesn’t require the use of a PrimaryPart.


CFrame.fromEulerAnglesXYZ() is equivalent to CFrame.Angles().

That worked! Thank you so much :slight_smile:

1 Like