Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Zombie Spawners not working?

I have a folder " Spawners" in the workspace with multiple parts called "1", "2".., but it does not work with the script below. It said "Workspace.Spawners.Script:6: attempt to index number with 'Value'.

local Spawners = script.Parent:GetChildren()
 local Zombie = game.ReplicatedStorage["Zombie"]
  while true do
 local SpawnChosen = math.random(1,#Spawners)
 for i, v in pairs(Spawners) do
 if v.Name == SpawnChosen.Value then
 local Clone = Zombie:Clone()
 Zombie.UpperTorso.CFrame = v.CFrame
 end
 end
 wait(1)
 end

2 comments

1

Zombie.UpperTorso.CFrame = v.CFrame -- I put parts in the workspace. So , is it gonna teleport clone to where parts are

0

try the new code i posted :) i think the problem was that 'v' and 'SpawnChosen' were different variables and so you cant compare them so i just inverted both of them to strings before comparing hope i helped! tell me if it works. 

2 answers

✓ Accepted answer

EDIT: try this, it works for me, for this to work you have to group the spawners together and put the zombie model inside ServerStorage :

local Spawners = game.Workspace.Spawners:GetChildren()--Change '.Spawners.' to whatever your model with your spawners inside is called
local Zombie = game.ServerStorage.Zombie
while true do
	local SpawnChosen = math.random(1,#Spawners)
	for i, v in pairs(Spawners) do
		print (i)
		if tostring(v) == tostring(SpawnChosen) then
			local Clone = Zombie:Clone()
			Clone.Parent=game.Workspace
			Clone.HumanoidRootPart.CFrame = v.CFrame
		end
	end
 	wait(1)
end

The problem was that 'v' and 'SpawnChosen' were different variables and so you cant compare them so i just inverted both of them to strings before comparing .
Also you need to move the Clone not the zombie and I believe its better to do instead of UpperTorso.CFrame = v.CFrame , HumanoidRootPart.CFrame.... in case you have a zombie that is R15 since HumanoidRootPart works for both r15 and r6 characters while uppertorso only works for r6

3 comments

0

it doesn't work. the problem lies in this line "if v.Name == SpawnChosen. Value". I appreciate tho. Thanks man

1

It works, but it only summon 1 zombie.

0

Does it not spawn a new zombie every 1 second? make sure the code is the same 

while true do
local Spawners = script.Parent:GetChildren()
 local Zombie = game.ReplicatedStorage.Zombie:Clone() --Clones The Zombie
 local SpawnChosen = math.random(1,#Spawners)
Zombie.Parent = workspace --Spawns It In
Zombie:moveTo(SpawnChosen.Position) --Moves It To The Chosen Spawner
 wait(1)
end

1 comment

0

Nice work. Way more simple and easy.

This discussion is preserved as it was. New answers, comments, and votes are closed.