I am making a queue logic. in my queue logic i want to make sure that if there is no free queue positions the NPC will start wandering. but my problem is that when it find a free position its not leaving that loop for some reason. i have tried a lot of ways to fix that but It didn’t worked, my last hope is you guys.
i will provide the prints:
hopefully someone can figure it out and help me:
function startWandering(npc)
if npc:GetAttribute("wandering") then
print(npc.Name .. " is already wandering.") -- Debug
return -- Prevent multiple wandering tasks
end
npc:SetAttribute("wandering", true)
print(npc.Name .. " started wandering.") -- Debug
while npc:GetAttribute("wandering") do
local freePosition, freeIndex = findFreeQueuePosition()
if freePosition then
print(npc.Name .. " found a free queue position at index " .. freeIndex) -- Debug
queue[freeIndex] = npc -- Assign NPC to the free queue position
moveToQueuePosition(npc, freePosition)
-- Make sure wandering stops after moving to a queue position
npc:SetAttribute("wandering", false)
print(npc.Name .. " has stopped wandering and moved to queue position " .. freeIndex) -- Debug
break
else
local randomPosition = Vector3.new(
math.random(wanderingArea.min.X, wanderingArea.max.X),
npc.HumanoidRootPart.Position.Y,
math.random(wanderingArea.min.Z, wanderingArea.max.Z)
)
--print(npc.Name .. " is wandering to random position " .. tostring(randomPosition)) -- Debug
moveToQueuePosition(npc, randomPosition)
wait(math.random(3, 5))
end
wait()
end
print(npc.Name .. " has exited the wandering loop.")
end
now that’s what happened when I finished serving the first queue customer:
as you can see the last one who was wandering named “Denis” moved to queue position number 4 and after that started wandering again!
the problem is that it’s not reading the attribute and not printing my debugs
where is my problem guys hopefully some one can help me ![]()

