I have a tool that does bombardement when triggered. This is the Script of the tool.
local Tool = script.Parent
Tool.RequiresHandle = false
local folder = Instance.new("Folder")
folder.Parent = game.Workspace
Tool.Activated:Connect(function(hit)
hit = Tool.Parent
print("It'll start sooner.")
wait(3)
local sayi = 0
while true do
sayi = sayi + 1
local a1 = Instance.new("Part")
a1.Shape = "Ball"
a1.Parent = folder
a1.Position = Vector3.new(math.random(-100,100),90,math.random(-100,100))
a1.Touched:Connect(function()
a1.CanCollide = true
local Pat = Instance.new("Explosion")
Pat.Parent = game.Workspace
Pat.Position = a1.Position
wait(0.5)
a1:Destroy()
end)
wait(0.2)
if sayi == 100 then
break
end
if hit.Humanoid.Health == 0 then
folder:Destroy()
end
end
end)
The script written above is simple; create a folder, instance 100 exploding balls and put them into the folder, repeat this whole day and destroy the folder as soon as the player dies because after respawn, the tool gets re-generated under the player's backpack so this also means there will be a new folder again.
Here comes the problematic part:
Whenever the player dies and respawns without using this tool, it generates one more folder again even though there was already one existing.
How can I solve this problem? I've tried 'for i, v in pairs' but didn't work, i guess i wrote it false.
Also I'm not sure whether the existence of too many folder might lag the game.
