How to make part spin locally!

Hello! I want to try to make tagged part spin locally! Here is my script in StarterCharacter so far:

This is a local script.

local CS = game:GetService("CollectionService")
local taggedParts = CS:GetTagged("starCirclet")
for _, part in pairs(taggedParts) do
	spawn(function()
			while true do
				part.CFrame = part.CFrame * CFrame.Angles(0, math.rad(4), 0)
				wait()
		end
	end)
end

Help are appreciated!

1 Like

What is the problem? It doesn’t spin? Are there any errors? Have you tried the code in a LocalScript, since

1 Like

The problem is it doesn’t spin. There are no errors. I’ve been trying to spin it in a local script. Sorry I didn’t state that out.

Try putting prints for us to be easier to understand where to problem is! As far as I know, loops don’t really work inside loops.

Is this how you put it? It didn’t print.

local CS = game:GetService("CollectionService")

local taggedParts = CS:GetTagged("starCirclet")

for _, part in pairs(taggedParts) do
	print("hi")
	spawn(function()
			while true do
				part.CFrame = part.CFrame * CFrame.Angles(0, math.rad(4), 0)
				wait()
		end
	end)
end
1 Like

So "hi" didn’t print, huh? Are you sure that there are parts tagged with "starCirclet"? Is the writing correct? These must be some reasons of why the loop doesn’t get anything.

Yes they are tagged, and the writing is right.

I don’t really know. You set tags on a LocalScript and the get tags script on a server side script?

It’s possible that the parts are tagged after your script has checked which parts have the starCirclet tag. In this case, you should look for some sort of TagAdded event that CollectionService offers.

Edit: This is the function:

In your case, I’d do this:

CollectionService:GetInstanceAddedSignal("starCirclet"):Connect(function(part)
     -- Run code here
end)

Spawn runs the function without being called, unlike coroutine.wrap()

1 Like

Maybe because u never called the function? I’ve never used the spawn thing

So do I use the spawn function? And also, I don’t think the line of script worked.

Yes, you can still use spawn. As for implementing my suggestion, I would suggest doing this:

local CS = game:GetService("CollectionService")
local taggedParts = CS:GetTagged("starCirclet")

local function makePartSpin(part)
      spawn(function()
			while true do
				part.CFrame *= CFrame.Angles(0, math.rad(4), 0)
				wait()
		end
	end)
end

for _, part in pairs(taggedParts) do
	makePartSpin(part)
end

CS:GetInstanceAddedSignal("starCirclet"):Connect(makePartSpin)

(Sorry if this counts as spoonfeeding, but I believe my prior explanation should also explain how it works, making it different from spoonfeeding)

2 Likes

It didn’t work again…sorry I’m making it hard on you.

1 Like

No need to apologise, don’t worry.

Try adding a print into the makePartSpin function to see if the function is called at all

I don’t think the function was called at all:

local CS = game:GetService("CollectionService")
local taggedParts = CS:GetTagged("starCirclet")

local function makePartSpin(part)
	print("hi")
	spawn(function()
		while true do
			part.CFrame *= CFrame.Angles(0, math.rad(4), 0)
			wait()
		end
	end)
end

for _, part in pairs(taggedParts) do
	makePartSpin(part)
end

CS:GetInstanceAddedSignal("starCirclet"):Connect(makePartSpin)

Try putting your script in starter player scripts, not sure if this will work but it’s worth a try

Could I see your method of tagging starCirclets?

I’ve tried that and I don’t think it worked.

I use the plugin that tags them (The Tag Editor)

Is your script disabled? Maybe try printing out the number of tagged parts you get from your script, and perhaps putting a print function at the top of your script