How to make a CFrame stop for a certain amount of time

I want to make it so that a model will stop moving for a certain amount of time, but I don’t know a lot about CFrame, so I don’t know how exactly to pull it off. Any pointers?
Here is script:

local Model = script.Parent
for i = 0,1,.001 do
	Model:SetPrimaryPartCFrame(Model:GetPrimaryPartCFrame() * CFrame.new(0,0,-i))
	wait(.01)
end
1 Like

Just put a higher wait, (You can do that or add a conditional to when you want that to happen.)

2 Likes

So would you like it if it stops then starts again, that can be done with an extra loop and a wait()

   local Model = script.Parent
   while true do wait(5) -- time it takes before starting again...
   for i = 0,1,.001 do
      Model:SetPrimaryPartCFrame(Model:GetPrimaryPartCFrame() * CFrame.new(0,0,-i))
      wait(.01)
    end
    end
2 Likes

also sorry for the indenting, I am fairly new at replying to posts.

2 Likes

When I used your script, the Model didn’t move at all. Why?

1 Like

it waits(5) in the start, you want it to stop for a certain amount of time, after 5 seconds it will restart and move

1 Like

I see. I should have been more clear in the title. I want the part to move for, 5 seconds, then stop for 5 seconds, then go again for 5 seconds. What should I do then?

In the loop you should make sure to change the i = 0,1,.001, edit it to satisfaction until it reaches 5 seconds, it is currently wrapped in a while true do loop which means it runs forever.

Neil I keep getting notifications from you… :flushed:

I have no idea what you did with your phone lel

1 Like

If you want an alternating script, you can use a boolean to keep track of when you want to move and stop.

Example:

local stop = false
while true do
    if stop then
        stop = not stop
        -- Nothing happens, just a switch on the bool
    else
        stop = not stop
        Model:SetPrimaryPartCFrame(...) -- moves model
    end
    wait()
end

In your case you are using a while loop instead, but it would be the same design.

Edit:

I realize that using a wait, you wouldn’t be able to move during the 5 seconds you are considering. You need an external timer to keep track of when you want to move the model.

local stop = false
while true do
    if not stop then
        Model:SetPrimaryPartCFrame(...)
    end
    wait()
end

.
.
.

local totalTime = 0
game:GetService("RunService").Heartbeat:Connect(function(timePassed)
    totalTime = totalTime + timePassed -- TimePassed is in seconds/frame
    if totalTime > 5 then -- 5 seconds have passed
        stop = not stop
        totalTime = 0
    end
end)
1 Like