How do i make a enemy left counter

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?

i want to get it to where say i kill a zombie it will change to 19 zombies left etc.

  1. What is the issue?
    i cant get it to change
    https://gyazo.com/af202d388f9f854975119edaa681d8c0

  2. What solutions have you tried so far?

i looked on youtube but all i could find was how to make a npc attack you which i already know how to do

Have a function that fires every time an enemy is killed. Make it lower the count by one, update the visible count for the players, and check if the count is zero. If the count is zero, run the code to move on to the next wave or whatever you want to do next.

You can detect when a zombie is removed from the zombie folder or the place where u store zombies, using:

Instance.DescendantRemoving:Connect(function(removing)
    if removing.Name == "Zombie" then --change this
        UpdateCounter() -- A function that updates the counter
    end
end)
1 Like

something like this would work

local zombie = workspace.Zombie
local ZombiesLeft = script.Parent.ZombiesLeft

zombie.Humanoid.Died:Connect(function()
     subtractZombie()
end

function subtractZombie()
      ZombiesLeft.Value = ZombiesLeft.Value - 1
      plr.PlayerGui.YOURTEXTBOX.Text = ("Zombies left: ")..ZombiesLeft.Value
end

also you would have to do some work to this script but it is your basis, use numbervalues, functions, and Humanoid.Died

1 Like

Create a numbervalue in workspace (i named it enemy) then in gui textlabel add localscript

while true do 
script.Parent.Text = "enemies(or smth u need to write extra): ".. game.Workspace.enemy.Value

After that you need script that will count amount of enemies or change it
I added a folder in workspace in that will be enemies after spawning so using this script in workspace again

local Folder = game.Workspace.Folder
local Count = game.Workspace.enemy

Folder.ChildAdded:Connect(function()
   Count.Value = Count.Value + 1
end)

Folder.ChildRemoved:Connect(function()
   Count.Value = Count.Value - 1
end)

Just make sure your enemy when dead is destroying and cloning into this folder