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

Help me with this script?

This only makes 1 zombie go to the position i want all the zombies there help?

	 local items = game.Workspace:GetChildren()
 for i,k in pairs(items) do
  if k.Name == "Zombie" then
   wait(5)
			BP = Instance.new("BodyPosition")
			BP.Name = "BoPo"
			BP.maxForce = Vector3.new(1000000, 1000000, 1000000)
			BP.position = script.Parent.Position
			BP.Parent = k.Torso
			wait(8)
			k.Torso.BoPo:remove()
  end
end

1 comment

0

Show a picture of the explorer.

1 answer

✓ Accepted answer

Simple, define BP locally:

     local items = game.Workspace:GetChildren()
 for i,k in pairs(items) do
  if k.Name == "Zombie" then
   wait(5)
            local BP = Instance.new("BodyPosition")
            BP.Name = "BoPo"
            BP.maxForce = Vector3.new(1000000, 1000000, 1000000)
            BP.position = script.Parent.Position
            BP.Parent = k.Torso
            wait(8)
            k.Torso.BoPo:remove()
  end
end

Turns out, it works just fine. I just tested it. Do you mean why does it only fetch one zombie at a time? Cause it gets them all. If so, then use coroutines:

    local items = game.Workspace:GetChildren()
 for i,k in pairs(items) do
  if k.Name == "Zombie" then
coroutine.resume(coroutine.create(function(a)
   wait(5)
            local BP = Instance.new("BodyPosition")
            BP.Name = "BoPo"
            BP.maxForce = Vector3.new(1000000, 1000000, 1000000)
            BP.position = script.Parent.Position
            BP.Parent = a.Torso
            wait(8)
            k.Torso.BoPo:remove()
end),k)
  end
end


2 comments

0

still only grabes 1 zombie

0

While defining it locally is a good idea, it won't actually affect anything in this case, since the previous BodyPosition gets clobbered on line 5.

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