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
When I go near the part, the "LinkedSword" clones itself infinitely into my backpack. How do I modify it so it'll become only 1 sword that is cloned into my backpack?
local Part=workspace.part local Sword=game.Lighting.LinkedSword while wait() 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(Sword.Name) then Sword:Clone().Parent=v.Backpack end end end end
That should work quite nicely.
The reason it was cloning it infinitely was because you were using a while loop, which repeatedly does something infinitely until you stop it with 'break' or 'return'. What I did was I made it so it only cloned the sword if the player didn't already have the sword.