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
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
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.
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)