Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Zombie Spawners not working?

Asked by 3 years ago
Edited 3 years ago

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
1
Zombie.UpperTorso.CFrame = v.CFrame -- I put parts in the workspace. So , is it gonna teleport clone to where parts are thinhs12 6 — 3y
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.  Mast3rStRix 43 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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

0
it doesn't work. the problem lies in this line "if v.Name == SpawnChosen. Value". I appreciate tho. Thanks man thinhs12 6 — 3y
1
It works, but it only summon 1 zombie. thinhs12 6 — 3y
0
Does it not spawn a new zombie every 1 second? make sure the code is the same  Mast3rStRix 43 — 3y
Ad
Log in to vote
1
Answered by 3 years ago
Edited 3 years ago
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
0
Nice work. Way more simple and easy. Mast3rStRix 43 — 3y

Answer this question