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

How do I stop the infinite cloning?

Asked by
Yeevivor4 155
9 years ago
local part = game.Workspace.Part
LinkedSword = game.Lighting.LinkedSword
while true do
    for i,v in pairs(game.Players:GetChildren()) do
        if (v.Character.Torso.Position - part.Position).magnitude <= 15 then
            c = game.Lighting.LinkedSword:clone()
             c.Parent = v.Backpack
          break

      end
  end

  wait()
  end

Whenever I get near the object, I clone the swords into my backpack infinitely. How do I do it so that it'll only clone into my backpack once.

2 answers

Log in to vote
0
Answered by
wjs3456 90
9 years ago

I don't know if this will fix it, but since you have already defined "Linked sword" up top you can use your variable down lower.

c = LinkedSword:clone

Ad
Log in to vote
0
Answered by
jakedies 315 Trusted Moderation Voter Administrator Community Moderator
9 years ago

Before you give them a tool, make sure they don't already own it.

local part = game.Workspace.Part
LinkedSword = game.Lighting.LinkedSword
while true do
    for i,v in pairs(game.Players:GetChildren()) do
        if (v.Character.Torso.Position - part.Position).magnitude <= 15 then
        if(not v.Backpack:FindFirstChild("LinkedSword")) then --If they don't own it
            c = game.Lighting.LinkedSword:clone()
             c.Parent = v.Backpack
        end
      end
  end

  wait()
  end

Answer this question