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
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
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