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