Rotate every part in a folder depending on distance from player

I am trying to make a script that rotates every part in a folder depending on how far away from the player it is (Capped at 60 degrees)

There are a few issues though, for one, the second tween does not play at all (It is intended to play after the first tween and do the exact opposite of what the first tween did), in addition to this, if the player gets closer to a part mid tween it causes it to change mid tween, which would not be an issue, except this causes the tween to not return the part to its original state.

I am not great with tweens or local scripts so this is very challenging for me, if anybody could help fix these bugs it would be greatly appreciated.

local ts = game:GetService("TweenService")

local info = TweenInfo.new(5, Enum.EasingStyle.Back, Enum.EasingDirection.InOut, 0, true)

local character = script.Parent
local map = workspace.map

while task.wait(5) do
	for i, part in map:GetChildren() do
		local magnitude = (part.Position-character.HumanoidRootPart.Position).Magnitude

		local properties = {CFrame = part.CFrame * CFrame.Angles(0, math.rad(math.min(60, magnitude)), 0)}
		local tween = ts:Create(part,info,properties)

		local properties2 = {CFrame = part.CFrame * CFrame.Angles(0, math.rad(-math.min(60, magnitude)), 0)}
		local tween2 = ts:Create(part, info, properties2)

		tween:Play()

		tween.Completed:Once(function()
			tween2:Play()
		end)
	end
end

There is a reverses property of TweenInfo that will reverse the tween immediately after it has been completed.

It looks like you have already set it to true, which might be conflicting with the second tween.

You can just remove the second tween entirely.

I mean, it looks like you’re making one, final calculation per loop.

I guess you could try setting the part back to its original position immediately after the for loop.

The second tween is not meant to undo the first tween, after the first tween has finished the second tween will rotate the part in the opposite direction.