This script is supposed to tween a part that has just been cloned and put into the workspace and also keep track of a part’s updated position because it is falling and changing position. I tried this method of keeping track of the position because for some reason it tweens to the original position that it was at when it spawns into the workspace. The same thing happens even when I update the position and I don’t know why.
local top = script.Parent.Top
local ts = game:GetService("TweenService")
local pos
local tweenInfo2 = TweenInfo.new(
.5,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
10
)
function update()
pos = top.Position
return pos
end
while true do
local counter = 0
update()
counter += 1
wait(.5)
print(pos)
if counter == 10 then
break
end
end
if script.Parent.Parent == game.Workspace then
local tween2 = ts:Create(top, tweenInfo2, {Position = Vector3.new(pos.X - 5, pos.Y, pos.Z)})
tween2:Play()
end
I added that while loop after seeing that the position was messed up. Regardless of whether or not I have it the position still goes to the origin of its placement into the workspace.
So basically you put the variable “counter” in the loop so the variable just reset every time.
Try that :
local top = script.Parent.Top
local ts = game:GetService("TweenService")
local pos
local tweenInfo2 = TweenInfo.new(
.5,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
10
)
function update()
pos = top.Position
return pos
end
local counter = 0
while true do
update()
counter += 1
wait(.5)
print(pos)
if counter == 10 then
break
end
end
if script.Parent.Parent == game.Workspace then
local tween2 = ts:Create(top, tweenInfo2, {Position = Vector3.new(pos.X - 5, pos.Y, pos.Z)})
tween2:Play()
end