Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Loop a part moving from point A to Point B?

lazer = script.Parent
lazerp = script.Parent.Position
lazerx = script.Parent.Position.X
lazery = script.Parent.Position.Y
lazerz = script.Parent.Position.Z
round = true

function forward()
    lazerp = Vector3.new(lazerx,lazery,lazerz+1)
    end    
function backward()
    lazerp = Vector3.new(lazerx,lazery,lazerz-1)
    end

while true do wait()
if lazerz >= -23 then backward() -- -23 is where the part's Z axis is supposed to stop at before heading back to -46--
elseif lazerz <= -46 then forward() -- -46 is where the part's Z axis begins at--
    
end
end

Attempting to move a part from point A to Point B No errors in output. Nothing happens in the game. Any help would be appreciated thanks.

2 comments

0

just use tweenservice instead

0

TweenService would make it much more easier, since it loops and reverses. Not only that, it also looks less jittery.

1 answer

this is how i done it

-- Set patrol delay at 2 seconds
local PATROL_DELAY = 1

-- Variables for the zombie and its humanoid
local GhostBall = game.Workspace["GhostBall"]
local humanoid = GhostBall.Humanoid

-- Variables for the point(s) the zombie should move between
local pointA = Vector3.new(1023, -2, 682) --game.Workspace["Part111"]
local pointB = Vector3.new(979, -2, 682) --game.Workspace["Part222"]
local pointC = Vector3.new(979, -2, 716) --game.Workspace["Part111"]
local pointD = Vector3.new(1023, -2, 716) --game.Workspace["Part222"]

-- Variable to keep track of the zombie's next destination
local nextDestinationObject = pointA


-- Loop to move between the two points
while wait(PATROL_DELAY) do
	humanoid:MoveTo(nextDestinationObject)
 
	-- Wait until the zombie has reached its target
	humanoid.MoveToFinished:Wait()
 
	-- Switch the current target to the other target
	if nextDestinationObject == pointA then
		nextDestinationObject = pointB
	elseif nextDestinationObject == pointB then
		nextDestinationObject = pointC
	elseif nextDestinationObject == pointC then
		nextDestinationObject = pointD
	elseif nextDestinationObject == pointD then
		nextDestinationObject = pointA
	end
	
end

1 comment

0

it walks to 4 point and then back to point 1/A

This discussion is preserved as it was. New answers, comments, and votes are closed.