Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

If i were to catch the end of a for loop, would this be right?

Asked by 6 years ago

Hi! The situation is: I'm lerping a model to move to another part The problem is: I can't figure out how to stop the for loop when the alpha (defined as i) of the lerp becomes a certain number.

Here's my code: (Ignore the comments, they aren't important to my problem/question)

01local model = script.Parent
02local dest = workspace.Solar_System.ShipReDirect1.Position
03local reDirect = script.ReDirect --tweak this when in real in-game script
04local StartCF = CFrame.new(model.PrimaryPart.Position,dest) --point model to destination
05 
06local function getRedirect()
07    --[[
08        The reDirect is when if a ship is going to another planet and it noclips throught the sun,
09        it will go to one part to avoid the sun, then when it reaches the redirect part, it heds off
10        to the planet of its choosen destination.
11    --]]
12    if dest == workspace.Solar_System.ToChoosePlanet1.Position then --Put in many more of these if then state.s in real script
13        reDirect.Value = workspace.Solar_System.ShipReDirect4      
14        StartCF = CFrame.new(model.PrimaryPart.Position,reDirect.Value.Position)
15    end
View all 29 lines...

I'm still working on the code, but if it's a little confusing i can send a picture of the physical thing and/or the Workspace or more explanation/code on it. Don't hesitate to ask please!

Thank you so much! :)

1 answer

Log in to vote
2
Answered by
MrMedian 160
6 years ago
Edited 6 years ago

Use break

1for i = 0, 1, 0.001 do
2    model:SetPrimaryPartCFrame(StartCF:lerp(EndCF,i))
3    if i == certainNumber then
4        break
5    end
6end
0
Thank you a bunch! Chez_Guy 67 — 6y
Ad

Answer this question