A way to count human/Humanoids my zombies humanoids are named Human so i can keep 10 spawned all at times, other than the other placeholders in the map that have respawn scripts. Ya it just stops after 10 are spawned
2. What is the issue? Include screenshots / videos if possible!
I need a way to count total humans in the place so i can return the TotalZombies.Value to 0 so it continues to spawn up to 10 zombies. I searched the forums any videos i could find and the dev wiki no luck. Thanks in Advance if you can help me with this
while wait (1) do
local v = script.Parent.TotalZombies
print (v.Value)
end
ZWS
local ServerStorage = game:GetService("ServerStorage")
local ZSMod = require(game.ServerScriptService.ZombieSpawnScripts.ZSMod)
while true do
wait(1)
ZSMod:SpawnZombies()
end
ZsMod
local ZSMod = {}
local SpawnLimit = 10
local ZombieCount = 0
local Path = script.Parent
function ZSMod:SpawnZombies()
local ZS = game:GetService("ServerStorage").ZombieSpawns
local RS = game.Workspace.ZombieSpawns
local Zombies = ZS:GetChildren()
local debris = game:GetService("Debris")
ZombieCount = Path.TotalZombies.Value
local RZS = RS:GetChildren()
for i=1, 3, 1 do
if ZombieCount < SpawnLimit then
local ZVal = Zombies[math.random(1, #Zombies)]--math.random(1,1)--#Zombies)
local SVal = RZS[math.random(1, #RZS)]
local Pos = SVal.Position
print(ZVal.Name)
local Zomb = ZVal:Clone()
Zomb.Parent = workspace
Zomb:MoveTo(Pos)
ZombieCount = ZombieCount + 1
Path.TotalZombies.Value = ZombieCount
print(ZombieCount)
print("Spawned 1")
-- while wait(10) do
-- if script.Parent.TotalZombies == 10 then
-- script.Parent.TotalZombies = 0
-- end
--end
end
end
-- debris:AddItem(ZVal)
end
return ZSMod
Before anything, I suggest working on the formatting for your first 2 scripts. Other than that, you can use game.Players:GetPlayers() or game.Players:GetChildren() to get the amount of players. It will check in game.Players but I hope that isn’t a problem!
for i,v in pairs(game.Players:GetChildren()) do
-- put your code here
end
For further explanation, you would use a loop - specifically, a for loop. While having ipairs / pairs as the iterating function.
You’ll then loop through the Workspace. (Instance where all 3D Objects will be rendered. A major part of all, if not the majority of the games across the platform).
While doing the loop, you’ll check if the (given name to the variable which represents the descendant of the Workspace.) has the wanted properties, to determine if it is a ‘zombie’ or not.
Your final code should look similar to this:
for Index, Value in ipairs(workspace:GetChildren()) do
-- Index is the index of value *Value*, which is going to be the child given by the loop.
-- Index won't matter much in this case, and really, most of the cases. So that's why most developers like to replace the first parameter (Index), with _
if Value.Property == Value then
-- Do stuff
end
end
I also would apologize for the lack of explanation - I hope I’ve helped you.
so i added a small script to count alive humans in the folder i made
–local ZSMod = {}
local ZSMod = {}
local SpawnLimit = 10
local ZombieCount = 0
local Path = script.Parent
function ZSMod:SpawnZombies()
local ZS = game:GetService(“ServerStorage”).ZombieSpawns
local RS = game.Workspace.ZombieSpawns
local Zombies = ZS:GetChildren()
local debris = game:GetService(“Debris”)
ZombieCount = Path.TotalZombies.Value
local RZS = RS:GetChildren()
for i=1, 1, 1 do
if ZombieCount < SpawnLimit then
local ZVal = Zombies[math.random(1, #Zombies)]–math.random(1,1)–#Zombies)
local SVal = RZS[math.random(1, #RZS)]
local Pos = SVal.Position
print(ZVal.Name)
local Zomb = ZVal:Clone()
Zomb.Parent = workspace.Ingamespawns
Zomb:MoveTo(Pos)
ZombieCount = ZombieCount + 1
Path.TotalZombies.Value = ZombieCount
print(ZombieCount)
print(“Spawned 1”)
for Index, Value in ipairs(workspace.Ingamespawns:GetChildren()) do
-- Index is the index of value *Value*, which is going to be the child given by the loop.
-- Index won't matter much in this case, and really, most of the cases. So that's why most developers like to replace the first parameter (Index), with _
if Value.Human == 0 then
ZombieCount = 0
-- Do stuff
end
end
end
end
-- debris:AddItem(ZVal)
end
return ZSMod
not getting anymore errors but i still cant get the count back to 0 tried a few variations
did some math stuff tried to subract 5 -10 from zombie count. Feel like im so close just missing something small