How do i make my zombies ''TargetNumber'' numbered in some sort of queue?

  1. I want to achieve so if a zombie gets a ‘‘TargetNumber’’ to like you know, when there is 3 zombies in a area i want to make them be like this. If there is 2 zombies for example, 1 zombie behind the first one has the ‘‘TargetNumber’’ Value to 2, and my main is goal to basically add accurate ‘‘TargetNumber’’ to my zombies to see what zombie is first,second,third,fourth and etc. in a queue line. like this for example.
    RobloxScreenShot20220727_182014406

  2. Issue is… i don’t HOW to code it.

  3. Eh, not so much. Tried Vector3, but, no.

1 Like

So to clarify, all you want to do is assign each Zombie a value that specifies which number they are in the queue of zombies?

1 Like

Yes, exactly what i meant.also 30 words

So you could
A. Assign them the queue number in Roblox studio by inserting an “IntValue” in their models called “TargetNumber” and put in the value manually.
B. You could loop through them and assign the value based on how close they are to the entrance part using Magnitude.

1 Like

i know IntValue, I said… HOW DO I script it? like to make zombies in orders by whos first and last

1 Like

There is actually a data structure you can use to achieve this functionality.

You have two options, you can use a stack(LIFO(Last in First Out)) or a Queue(First In First Out(FIFO))

I would use a Queue, I have written a priority queue that is open source. I will link it to you.

is it open-source? or is it like a tutorial how to make it.

I can also make a tutorial on my youtube if you need me to. But the concept is literally a line.

aight hopefully it works, if it does work ill make this a solution.

Let me code an easier one, give me 5min.

yeah thanks, its more advanced. i don’t even understand proxy on this script.

So you need a table that has all the zombies.

-- Variables Defined --
local Zombies = ZombieFolder:GetChildren() -- Made up folder of zombies.
local EntrancePart = part -- (the part that the first zombie is closest to)

-- Get Distance Of Zombies From the Entrance --
local function getDistance(zombie)
  local HumanoidRootPart = zombie.HumanoidRootPart
  return (EntrancePart.Position - HumanoidRootPart.Position).Magnitude
end

-- Sort the Zombies table according to their distances --
table.sort(Zombies, function(zombieA,zombieB)
  return getDistance(zombieA) < getDistance(zombieB)
end)

-- Assign their "TargetNumber" based on their order in the list --
for i = 1,#Zombies do
  Zombies[i].TargetNumber.Value = i
end

You pretty much add the Zombies in the order they are spawned. I have to go work on a commission but this should solve the problem.

alright, ill try. but it seems little confusing? explaination? (i know modules)
do i need to add zombies in order with this or somethin?

Ill make a youtube video, give me 15min

Queues || Data Structures #3 - YouTube Give it a few min, its uploading.

ok, ill be on the page. also i didn’t know you we’re an youtuber.

might be the solution, but i don’t understand Modules all of it. D:

Hello, have you tried this solution? Does it help you at all?