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

Can you think of a more efficient way of doing this MoveTo?

Asked by 4 years ago

Hello, im working on a script that moves the npc to different parts (named pos1, pos2..on and on) And the method im using for this looks really ugly and not efficient. So can anyone recommend some better ways of doing this?

Freddy = game.Workspace.NPCs.Freddy.Humanoid
fred1 = game.Workspace.FreddyPositions.pos1.Position
fred2 = game.Workspace.FreddyPositions.pos2.Position
fred3 = game.Workspace.FreddyPositions.pos3.Position
fred4 = game.Workspace.FreddyPositions.pos4.Position
fred5 = game.Workspace.FreddyPositions.pos5.Position
fred6 = game.Workspace.FreddyPositions.pos6.Position
fred7 = game.Workspace.FreddyPositions.pos7.Position
fred8 = game.Workspace.FreddyPositions.pos8.Position

Freddy:MoveTo(fred1)
Freddy.MoveToFinished:wait()
Freddy:MoveTo(fred2)

-- on and on and on

Thank you for the help! By the way, fred1, 2, etc. Are all different parts placed around that he moves to. The way im doing this already works, but I need to know if theres a better way since I am going to have alot more than just 8 positions.

1
since they are in numerical order, you can wrap it in a numeric for loop theking48989987 2147 — 4y
0
something like "for i = 1, 8 do Freddy:MoveTo(FreddyPositions["pos"..i]) end" theking48989987 2147 — 4y

Answer this question