NPC ordering system not working properly

I am trying to make a NPC ordering system like the one seen in many games, such as Bloxburg. The problem that I am experiencing is the fact that the rigs do not move up if one is removed.

This is what I got so far, and the problem is seen in this video below;


local pointTable = {workspace.DestinationPart1, workspace.DestinationPart3, workspace.DestinationPart5}
local rigTableA = {}
local rigTableB = {}
local rigTableC = {}

local tickStarted
function checkTimer(rigTable, destinationPart, lastTime)
	if rigTable[1] then
		if not tickStarted then
			last = tick()
			tickStarted = true
		end
		if tick() - lastTime >= 5 and rigTable[1] ~= nil then
			rigTable[1].Humanoid:MoveTo(workspace.LeavingShop.Position)
			rigTable[1]:Destroy()

			table.remove(rigTable, 1)
			newRig(rigTable, destinationPart)
			tickStarted = false
			last = tick()
		end
	end
end

function newRig(rigTable, DESTINATION_POINT)
	for index, rigs in pairs(rigTable) do
		local TARGET = DESTINATION_POINT.CFrame * Vector3.new(0, 0, 4 * index)
		rigs.Humanoid:MoveTo(TARGET)
	end
end

game:GetService("RunService").Heartbeat:Connect(function()
	checkTimer(rigTableA, workspace.DestinationPart2, last)
end)

function Aftermath(DestinationPoint, rigTable, rigModel, humanoid)
	local targetPos = DestinationPoint.CFrame * Vector3.new(0,0,4 * #rigTable)
	humanoid:MoveTo(targetPos)
	humanoid.MoveToFinished:Wait()
	table.insert(rigTable, rigModel)
end


while true do 
	wait(1)
	local destination = pointTable[math.random(1,#pointTable)]
	local pickedPoint = workspace.DestinationPart1
	local rigModel = game.ReplicatedStorage.Others.rigmodel:Clone()
	local humanoid = rigModel.Humanoid
	rigModel.Parent = workspace
	humanoid:MoveTo(pickedPoint.Position)


	if pickedPoint == workspace.DestinationPart1 then
		humanoid:MoveTo(workspace.FlatPoint1.Position)
		humanoid.MoveToFinished:Wait()
		Aftermath(workspace.DestinationPart2, rigTableA, rigModel, humanoid)
		if rigModel == rigTableA[1] then
			last = tick()
			tickStarted = true
		end
	end

If anyone could help it would be greatly appreciated. This isn’t the entire script as the rest of it doesn’t have anything to do with my problem, but if I left something out, let me know.

So your problem is that the rig didn’t exactly move up when the other customer are removed?

Yeah, when the first one in the line is removed, the others don’t go up

so in my head is this simple solution
get a total amount of customer that in a current line
checks when a total amount of customer in a line is 0
ended a checking loop, spawns customer, and start a loop again.

Are you agreed with this?

I don’t understand what you mean. Are you saying once there is zero NPCs in the line, I should end the Timer loop? Because, if so, I’m doing that already. (At least, pretty sure, I haven’t touched this script for a while cus I gave up on it.)

let me go write in the studio real quick! be right back.

Ok i got it!
This is what my detection works
Solutions
NOTE: this is what it looked and i forgot to delete Total and the other script inside a script and it useless so you don’t need it(you know?)

A script:

local customer = game.Lighting.Customer:Clone()
customer.Parent = game.Workspace.CustomerFolder
while wait() do
if script.InDetection.Value == false then
script.InDetection.Value = true
script.Empty.Value = true
for i,v in pairs(game.Workspace.CustomerFolder:GetChildren()) do
script.Empty.Value = false
end
if script.Empty.Value == true then
local customer = game.Lighting.Customer:Clone()
customer.Parent = game.Workspace.CustomerFolder
else
print(“There is customer existing”)
end
script.InDetection.Value = false
end
end

Check it out if it working or no!

1 Like