Why this handler is not working

this is my spinning brick script ,but its not spinning
local CollectionService = game:GetService(“CollectionService”)

local TaggedPart = CollectionService:GetTagged(“spinning”)

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

end

Hi XxAwesomeDabxX.
Remember to add a wait() in the infinite loops. Otherwise it might not work, or even crash Studio.

local CollectionService = game:GetService("CollectionService")

local TaggedPart = CollectionService:GetTagged("spinning")

for _, TaggedPart in pairs(TaggedPart) do
while true do
TaggedPart.CFrame = TaggedPart.CFrame * CFrame.fromEulerAnglesXYZ(0.0,0.1,0.0)
wait(1) -- Replace 1 with the time you consider necessary.
end
end

If this still does not solve your problem, let me know.


Also if you are using “while wait() do” loops, I recommend looking at this post.

still not working--------------------------------------------

So I recommend you, if you have not already done so, look at this Wiki article so you can better understand how the CollectionService is used.


This code should serve you, but you should put it inside the block you want to spin.

while true do
 script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0.0,0.0,0.0)
 wait()
end

@XxAwesomeDabxX Try changing the name of the variable, like this:
(I have tried it and this works.)

local CollectionService = game:GetService("CollectionService")

local TaggedParts = CollectionService:GetTagged("spinning")

for _, TaggedPart in pairs(TaggedParts) do
while true do
TaggedPart.CFrame = TaggedPart.CFrame * CFrame.fromEulerAnglesXYZ(0.0,0.1,0.0)
wait(1) -- Replace 1 with the time you consider necessary.
end
end

Likewise, what you may be doing wrong is to assign the blocks their tag. I recommend using this plugin to do this.

You’re missing something. It’s only turning one part because the loop isn’t ending. Try this:

local CollectionService = game:GetService("CollectionService")

local TaggedParts = CollectionService:GetTagged("spinning")

while wait(1) do
    for _, TaggedPart in pairs(TaggedParts) do
        TaggedPart.CFrame = TaggedPart.CFrame * CFrame.fromEulerAnglesXYZ(0.0,0.1,0.0)
    end
end

You could also do the method that you mentioned but with coroutines, but personally for me this is easier to understand.

Edit: I don’t suggest using while wait(n) loops.

2 Likes

I would highly recommend using CFrame.Angles()
An example would be :

Part.CFrame = Part.CFrame * CFrame.Angles(math.rad(degrees),0,0)

local folder = workspace:FindFirstChild(“Spinningbrick”)

while true do
wait()
for i,v in pairs(folder:GetChildren()) do
v.CFrame = v.CFrame * CFrame.fromEulerAnglesXYZ(0.0,0.1,0.0)
end
end

2 Likes