Spawn multiple zombies my command

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

  1. What do you want to achieve? Keep it simple and clear!
  • Script that spawns multiple zombies when you chat for example,
    “/spawn ZombieName 50”
  1. What is the issue? Include screenshots / videos if possible!
  • No videos/screenshots but it just doesn’t work, no errors.
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
  • I looked alot but none helped me.

Here is the code i tried.


game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(chat)
		for i, v in pairs(game.Players:GetPlayers()) do
			if v.Name == "JmPopYT" or v.Name == "14xqvxzy" then
				local chatSplit = chat:split()
				
				if chatSplit[1] == "/spawn Zombie" then
					for i = 1, chatSplit[2] do
						local zombie = game.ReplicatedStorage.Zombies.Zombie:Clone()
						zombie.Parent = workspace
						zombie:PivotTo(plr.Character:WaitForChild("HumanoidRootPart").CFrame)
					end
				end
			end
		end	
	end)
end)	

Thanks, ~Pop

If you chat “/spawn Zombie 50”, the chat:split() will become this:

local chatSplit = {
    "/spawn",
    "Zombie",
    "50"
}

The problem is that you check if chatSplit[1] == “/spawn Zombie” which isn’t possible since the chat message got split. The if statement should be:

if chatSplit[1] == "/spawn" and chatSplit[2] == "Zombie" and tonumber(chatSplit[3]) then
3 Likes

Alright but,
it still does not spawn the zombies by the amount i want.

I’ve tried modifying

for i = 1, chatSplit[2] do

to

for i = 1, chatSplit[3] do

but still nothing.

Since the chatSplit is only an array of strings, you’ll have to turn it into a number. You can do this by changing it to:

for i = 1, tonumber(chatSplit[3]) do

Also I edited my previous reply to include another check in the if statement to make sure it actually is a number.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.