Need Help Tweening Items in a Group

I am trying to tween spawn meshes I made to give them some class. However, it isnt working. All these items are in a group and I want to tween them all at once using a for/in loop.

local ts = game:GetService("TweenService")
local spawnmeshes = script.Parent.SpawnMeshes:GetChildren()






local tweeninfo1 = TweenInfo.new(
	5,
	Enum.EasingStyle.Quad,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

local tweeninfo2 = TweenInfo.new(
	5,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

local Properties1 = {
	Orientation = 0, math.random(0,360), 0
}

local Properties2 = {
	Color = Color3(math.random(0,255), math.random(0,255), math.random(0,255)) -- line 32; where the error is.
}

for i,n in pairs(spawnmeshes) do
	local Tween = ts:Create(n, tweeninfo1, Properties1)
end

for i,n in pairs(spawnmeshes) do
	local Tween = ts:Create(n, tweeninfo2, Properties2)
end

The error I’m getting is: Workspace.SpawnArea.SpawnMeshAnimation:32: attempt to call a table value
If anyone knows, please give it a shot! Thanks!

1 Like

Errors:

  • You are not editing the Color3 from RGB.
  • You are not playing tweens.
  • It’s not an error but it’s better to use Random.new()

So the properties2 table should be:

local Seed = Random.new()

local Properties2 = {

    Color = Color3.fromRGB(Seed:NextInteger(0, 255), Seed:NextInteger(0, 255), Seed:NextInteger(0, 255))

}

And the for loops should be:

for i, n in pairs(spawnmeshes) do
   local Tween = ts:Create(n, tweeninfo1, Properties1)

   Tween:Play()
end

for i, n in pairs(spawnmeshes) do
   local Tween = ts:Create(n, tweeninfo2, Properties2)

   Tween:Play()
end
1 Like

I followed your advice, but the initial error still isn’t fixed.
Its telling me at the line where I set the orientation, that I had an attempt to call a table value.

1 Like

Oh sorry, I didn’t see that error. The problem is that you didn’t set orientation as a Vector3 value:

local Properties1 = {

    Orientation = Vector3.new(0, Seed:NextInteger(0, 360), 0)

}
1 Like

You’re right, it worked! Thank you.
But now, all the meshes do the same thing.
What do I have to change to make them all go to a different color/direction?

To do that, you should put the table inside of the for loop, so it can give a new value each time that the loop repeats:

local Seed = Random.new()

for i, n in pairs(spawnmeshes) do
	local Properties1 = {
		Orientation = Vector3.new(0, Seed:NextInteger(0, 360), 0)
	}
	
	local Tween = ts:Create(n, tweeninfo1, Properties1)
	Tween:Play()
end

for i, n in pairs(spawnmeshes) do
	local Properties2 = {
		Color = Color3.fromRGB(Seed:NextInteger(0, 255), Seed:NextInteger(0, 255), Seed:NextInteger(0, 255))
	}

	local Tween = ts:Create(n, tweeninfo2, Properties2)
	Tween:Play()
end
1 Like

It worked!
I appreciate your time and effort, and have a great day.

1 Like