local locations = {script.Parent.Parent.Location1, script.Parent.Parent.Location2, script.Parent.Parent.Location3, script.Parent.Parent.Location4, script.Parent.Parent.Location5, script.Parent.Parent.Location6}
for i, location in ipairs(locations) do
if not location then
-- If a location is not found, print an error message and continue to the next iteration
print("Error: Location " .. i .. " not found")
continue
end
local success, errorMessage = pcall(function()
-- Move the Caroid object smoothly between the locations using TweenPosition
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local tween = TweenService:Create(script.Parent.Caroid, tweenInfo, {Position = location.Position})
tween:Play()
-- Wait for the movement to finish
tween.Completed:Wait()
end)
if not success then
-- If an error occurs, print the error message
print(errorMessage)
end
end
This code uses a for loop to loop through each location in the locations table and moves the Caroid object smoothly between the locations using the TweenPosition function. It then waits for the movement to finish before continuing to the next iteration. The code also uses the pcall() function to catch any errors that might occur and prints an error message if an error occurs.
I also wanted to mention that using a for loop is generally better than using a while true loop in this situation because it allows you to loop through a specific set of values rather than running an infinite loop.
now as you can see, the script breaks at minute 1:00, but if i just go in the script and click play, it works. what’s wrong with it?
thanks
I would recommend you to use MoveToAsync() instead of MoveTo(). When you use MoveTo() function the script is paused until the Movement is done. But if you use MoveToAsync(), the script is not paused. This way you can avoid the problem you are facing.