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
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
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.
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()
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)
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)
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