How would I fix these stopped bricks

Hi, I have problems with these stopped bricks and I want them to become neutral.
I’ve tried lots but still not, also find this problem in DevForum already but still not.

Here’s the video The video is a little delayed, also the bricks do not teleport

robloxapp-////-////.wmv (2.5 MB)

Here’s my script

--// MovingAnim
local TweenService = game:GetService("TweenService")
--local MovingInfo = TweenInfo.new(Time,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut)
--// Service 
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--// Variables
local Pathways = workspace.PathWay
local allDes = #Pathways:GetChildren()-1
--local TotalNPCS = {}

function DestroyNPC(NPC)
	wait(.05)
	NPC:Destroy()
	--[[for i,v in pairs(TotalNPCS) do
		if v == NPC then
			table.remove(TotalNPCS,i)
		end
	end]]
end

function MoveToNext(NPC,Station)
	--spawn(function()
	if NPC:WaitForChild("CurrentPoint").Value >= 1 and NPC:WaitForChild("CurrentPoint").Value <= allDes+1 then
		--print("Walking")
		local Time = (Pathways["D"..NPC.CurrentPoint.Value-1].Position-Station.Position).magnitude/NPC.Speed.Value
		NPC.Time.Value = Time
		local move = TweenService:Create(NPC,TweenInfo.new(Time,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut),{Position = Vector3.new(Station.Position.X,NPC.Size.Y*0.5+0.5,Station.Position.Z)})
		move:Play()
		move.Completed:connect(function()
			warn("Done")
			NPC.moveable.Value = true
			NPC.CFrame = Station.CFrame + Vector3.new(0,NPC.Size.Y*0.5-0.5,0)
			NPC.CurrentPoint.Value +=1
			if NPC.CurrentPoint.Value == allDes+1 then
				DestroyNPC(NPC)
			end
		end)

	elseif NPC:WaitForChild("CurrentPoint").Value == 0 then
		NPC.moveable.Value = true
		NPC.CFrame = Station.CFrame
		NPC.CurrentPoint.Value +=1

	end
--	end)
end

function ControlNPC(NPC)
	spawn(function()
	for i=0,allDes+1 do
		if NPC:WaitForChild("moveable").Value == true then

			print(i)
			print("Pass")
			if NPC:WaitForChild("CurrentPoint").Value >= 0 and NPC:WaitForChild("CurrentPoint").Value <= allDes then
				NPC.moveable.Value = false
				MoveToNext(NPC,Pathways["D"..NPC:WaitForChild("CurrentPoint").Value])	
				print("St2")
			end
		end
		wait(NPC.Time.Value)
	end
	end)
end


function SpawnNPC(NPC)
	spawn(function()
		local new = ReplicatedStorage.NPCs[NPC]:Clone()
		new.Parent = workspace
		ControlNPC(new)
	end)
end

--// Spawwning Enemieseadae
wait(3)

SpawnNPC("NPC1")
wait(2)
SpawnNPC("NPC1")
wait(2)
SpawnNPC("NPC1")
wait(1)
SpawnNPC("NPC2")
wait(1)
SpawnNPC("NPC2")
wait(1)
SpawnNPC("NPC2")
wait(1)
SpawnNPC("NPC2")
--[[table.insert(TotalNPCS,NPC)
spawn(function()


	ControlNPC(NPC)
end
wait(NPC.Time.Value)

end
end)]]--

The output shows no error

Maybe try this?

--// MovingAnim
local TweenService = game:GetService("TweenService")
--local MovingInfo = TweenInfo.new(Time,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut)
--// Service 
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--// Variables
local Pathways = workspace.PathWay
local allDes = #Pathways:GetChildren()-1
--local TotalNPCS = {}

function DestroyNPC(NPC)
	wait(.05)
	NPC:Destroy()
	--[[for i,v in pairs(TotalNPCS) do
		if v == NPC then
			table.remove(TotalNPCS,i)
		end
	end]]
end

function MoveToNext(NPC,Station)
	coroutine.wrap(function()
		local point = NPC:WaitForChild("CurrentPoint")
		if point.Value >= 1 and point.Value <= allDes+1 then
			--print("Walking")
			local Time = (Pathways["D"..point.Value-1].Position-Station.Position).magnitude/NPC.Speed.Value
			NPC.Time.Value = Time
			local move = TweenService:Create(NPC,TweenInfo.new(Time,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut),{Position = Vector3.new(Station.Position.X,NPC.Size.Y*0.5+0.5,Station.Position.Z)})
			move:Play()
			move.Completed:connect(function()
				warn("Done")
				NPC.moveable.Value = true
				NPC.CFrame = Station.CFrame + Vector3.new(0,NPC.Size.Y*0.5-0.5,0)
				point.Value +=1
				if NPC.CurrentPoint.Value == allDes+1 then
					DestroyNPC(NPC)
				end
			end)
		elseif point.Value == 0 then
			NPC.moveable.Value = true
			NPC.CFrame = Station.CFrame
			point.Value +=1
		end
	end)()
end

function ControlNPC(NPC)
	coroutine.wrap(function()
		local point = NPC:WaitForChild("CurrentPoint")
		local moveable = NPC:WaitForChild("moveable")
		for i= 0, allDes+1 do
			if moveable.Value then
				print(i)
				print("Pass")
				if point.Value >= 0 and point.Value <= allDes then
					moveable.Value = false
					MoveToNext(NPC,Pathways["D"..point.Value])	
					print("St2")
				end
			end
			wait(NPC.Time.Value)
		end
	end)()
end


function SpawnNPC(NPC)
	coroutine.wrap(function()
		local new = ReplicatedStorage.NPCs[NPC]:Clone()
		new.Parent = workspace
		ControlNPC(new)
	end)()
end

--// Spawwning Enemieseadae
wait(3)

SpawnNPC("NPC1")
wait(2)
SpawnNPC("NPC1")
wait(2)
SpawnNPC("NPC1")
wait(1)
SpawnNPC("NPC2")
wait(1)
SpawnNPC("NPC2")
wait(1)
SpawnNPC("NPC2")
wait(1)
SpawnNPC("NPC2")
--[[table.insert(TotalNPCS,NPC)
spawn(function()


	ControlNPC(NPC)
end
wait(NPC.Time.Value)

end
end)]]--

Not sure how helpful using Coroutines in this case will be instead of spawn

1 Like

Still not working, actually. But thank you.

I’ve addded wait() at for loop and it’s now working thank you :smile:

1 Like