Spawning more than 1 type of entity issue (Solved. Kinda)

SOLVED (Kinda): It was because the code was having issue figuring out which type of entities. In the folder described below, everything in ‘ZombiesInGame’ was called ‘Zombie’ so I guess the code couldn’t ‘Get Children’ correctly because it thought there was 1 maybe?

So I can’t add ALL the code, otherwise my game will be easily replicated. And even though its basic, idk I just don’t wanna release- anywho!

The issue is simple, I just lack the ability to solve it.

BASICALLY. I want my script to pick a random ‘Zombie’ from my replicated storage folder and spawn it.
My system atm works perfectly but when I tried to code it to pick multiple; that’s where I faltered.

I just want the script to choose a ‘zombie’ from the folder at random and spawn it in. Just so the map has variety than just 1 simple green and brown zamble xD


local spawn = script.Parent.Locations (Parts used as Spawnplates, just regular parts)

for _, spwn in pairs(spawn:GetChildren()) do
				if spwn:IsA('BasePart') then
					local Max = ZombieTypes:GetChildren()
					if #Max == 0 then continue end
					local zombieCopy = ZombieTypes[math.random(1, #Max)]:Clone() -- It's here, script logs give me random numbers (7,22,14 etc... I only have 5 Zombies to choose from).

					zombieCopy.Parent = zombiesInGame -- This is an empty folder that the replicated storage Clones them too. I can't add this part of the code but it's not part of the issue.

					zombieCopy.HumanoidRootPart.CFrame = +,1,0))
                    zombieCopy.Humanoid.Health = health
                    zombieCopy.Configuration.AttackDamage.Value = damageTotal

Any solutions or Ideas is appreciated. I’m novice at coding so I apologize if my code is crop. If you need any more information I will provide.

This seems to be the error. If you’re getting a child, you need to use the :GetChildren() function.

local zombieCopy = Max[math.random(1, #Max)]:Clone()

Hey! Thank you so much! :smiley: that cleared the issue, however now it’s giving me this error on this line:

"HumanoidRootPart is not a valid member of MeshPart “Workspace.Spawns.ZombiesInGame.RightFoot”

zombieCopy.HumanoidRootPart.CFrame = +,1,0)) 

I don’t know why as to what the code lines up as- It should just go from ‘Zombie’ → HumanoidRootPart. idk why its calling the foot (and presuming any bodypart).

If you happen to know why, Id appreciate it :smiley:

Assuming the error you posted is related to the line of code you mentioned, then zombieCopy is being defined as workspace.Spawns.ZombiesInGame["Right Foot"].

An easy way to debug this is with print statements. Just do print(zombieCopy, zombieCopy.Parent) etc throughout the points in which the code is shooting an error and it’ll show you why or what is happening.

1 Like

Sorry for my delay in response. Did what you said, with complete respect, it didn’t help solve much- but I did come across the issue. They just needed different names in the folder “A,B,C etc”. I don’t know how changing the names “ZombieA” “ZombieB” etc works. Merely because the code is just looking for things named ‘Zombie’… but Im glad its solved.

Thank you for helping out :smiley:

1 Like