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

How do I stop the infinite cloning?

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

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

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

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