Help making tweened object Transparent in between for-loop running within a while loop

  1. I’m tweening an object using positions in a table of invisible blocks to move the object in a straight line. I’m using a for-loop to iterate through the positions. The for-loop runs in a continuous while-loop so the object returns to the start position after finishing the for-loop.

  2. When the last position is reached in the for-loop, the object goes back to the first position to start the for-loop again. I’m trying to make the object transparent when it travels back to where it started, and then visible again when the next for-loop starts to move the object down the line again.

  3. The problem is I can’t make the object transparent for its return trip to the starting position. I tried setting the transparency to 1 outside the for-loop right before the end of the while-loop. It goes transparent briefly, but appears again when it moves back up the line to the starting position. Same thing happens if I try to Cancel the tween outside the for-loop at the end.

task.defer(function()
while true do
local newCFrame = nil
for i=1, totalWaypoints do
local newPosition = waypoints[i].Position
newCFrame = CFrame.new(newPosition) * blob.CFrame.Rotation
tween = TweenService:Create(blob, info, {CFrame=newCFrame})
blob.Transparency = 0
blob.CanCollide = true
tween:Play()
tween.Completed:Wait()
end – end of for loop
task.wait(1)
blob.Transparency = 1
blob.CanCollide = false
task.wait(3)
end – end of while loop
end)

Do you have a video to explain what you’re trying to do? I’m a little bit confused on what the issue is exactly.

1 Like

My guess would be this is setting its transparency back to 0 right as the object moves, which is why its becoming visible again as it starts moving.
Why not just directly set the part’s position back to its start? Heres my take on things

while true do
  local newCFrame = nil
  for i=2, totalWaypoints do --skip the first waypoint, since im assuming its the start pos
    local newPosition = waypoints[i].Position
    newCFrame = CFrame.new(newPosition) * blob.CFrame.Rotation
    tween = TweenService:Create(blob, info, {CFrame=newCFrame})
    tween:Play()
    tween.Completed:Wait()
  end
  task.wait(1)
  blob.Transparency = 1
  task.wait(3)
  blob.CFrame = CFrame.new(waypoints[1].Position) * blob.CFrame.Rotation --now just directly reposition it back to the start
  blob.Transparency = 0
end

by the way, did you know that partitioning your code with " ``` "s will format it nicely? makes it a lot easier to post code here + indent it in a readable way

Thank you!
I never thought about repositioning it back to its starting position.
Also appreciate the tip about using quotes for code. This is the first time I posted code.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.