Can tweens work with Tag Editor?

Hi, I have been trying to make a Tag with the Tag Editor plugin and it seems that only one of the Tagged objects can do the Tween can anyone help me with this?

local CollectionService = game:GetService(“CollectionService”)

local TaggedParts = CollectionService:GetTagged(“SpinningObject”)

for _, TaggedPart in pairs(TaggedParts) do

TweenService = game:GetService("TweenService")
spininfo = TweenInfo.new(2,Enum.EasingStyle.Linear)

Spin1 = TweenService:Create(TaggedPart,spininfo,{CFrame = TaggedPart.CFrame * CFrame.Angles(0,math.rad(120),0)})
Spin2 = TweenService:Create(TaggedPart,spininfo,{CFrame = TaggedPart.CFrame * CFrame.Angles(0,math.rad(240),0)})
Spin3 = TweenService:Create(TaggedPart,spininfo,{CFrame = TaggedPart.CFrame * CFrame.Angles(0,math.rad(360),0)})

Spin1:Play()
Spin1.Completed:Connect(function()Spin2:Play() end)
Spin2.Completed:Connect(function()Spin3:Play() end)
Spin3.Completed:Connect(function()Spin1:Play() end)

end

https://gyazo.com/ff694472b6c0a9c50e6f7794d95a4bf5

Your Spin1, Spin2, and Spin3 variables are global, and thus are being overridden each time you loop through a new tagged part. Change those to local variables and you should be good to go.

local Spin1 = TweenService...
local Spin2 = TweenService...
local Spin2 = TweenService...

By making them local, those variables will only exist within the scope of that loop (known as lexical scoping).

A good rule of thumb is to always use local when defining a new variable.

1 Like