Block stops moving before reaching end of trajectory?

I got this script which makes a part move from “Destination 1” to “Destination 2”, however it appears to not move when there is another part present in the way, I don’t understand why.

Here's the hierarchy of the scripts and parts in the explorer

image

.

Here's the script ("Settings")
local moveDelay = 3
local topSpeed = 15
local hideDestinationBlocks = true

local mainFolder = script.Parent
local platform = mainFolder.MovingPlatform
local alignPosition = platform.AlignPosition

local positionList = {}

while true do
	local lowest = {nil, math.huge}

	for _, value in pairs(mainFolder:GetChildren()) do
		if not value:IsA("BasePart") then
			continue
		end

		local nameSplit = string.split(value.Name, " ")

		if #nameSplit ~= 2 then
			continue
		end

		local destinationNumber = tonumber(nameSplit[2])

		if string.lower(nameSplit[1]) == "destination" and destinationNumber and destinationNumber < lowest[2] then
			lowest = {value, destinationNumber}
		end
	end

	if not lowest[1] then
		break
	else
		table.insert(positionList, lowest[1].Position)

		if hideDestinationBlocks then
			lowest[1]:Destroy()
		else
			lowest[1].Name = "Destination"
		end
	end
end

alignPosition.MaxVelocity = topSpeed
alignPosition.Position = positionList[1]
platform.AlignOrientation.CFrame = platform.CFrame.Rotation
platform.Anchored = false

local currentIndex = 1

while true do
	alignPosition.Position = positionList[currentIndex]
	task.wait(moveDelay)

	currentIndex = currentIndex % #positionList + 1
end

.

And here's a video of the block not going from position 1 to 2 (the big white blocks)

What can I do to make it so that the block “ignores” the other block and goes straight from “Destination 1” to “Destination 2”?

2 Likes

i may be wrong, but it appears its doing as asked, it doesn’t reach the other position because moveDelay is 3 seconds and it seems to be moving back and forth every 3 seconds. calculate how long it’ll take between each position by doing distance of the block from the goal divided by the topSpeed value to get the time it’ll take to traverse before going back.

Try using:

while true do
	alignPosition.Position = positionList[currentIndex]
	while alignPosition.Position ~= positionList[currentIndex] do task.wait() end -- Yields until reached

	currentIndex = currentIndex % #positionList + 1
end
1 Like

It worked but now once the wall reaches one of the destination blocks it just stops moving permanently

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.