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

Help me with this script?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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
0
Show a picture of the explorer. EzraNehemiah_TF2 3552 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

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


0
still only grabes 1 zombie Anthony9960 210 — 9y
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. BlueTaslem 18071 — 9y
Ad

Answer this question