Hi, thank you for reading. What I'm trying to do here is that after every 2 seconds, if there is no object in workspaced named "Foil", then the script will fire and a "Foil" from Lighting will clone into the workspace. The problem is that it keeps spawning the foil after I removed it when I clicked it. It just spawns infinitely and it bothers me that it does that. Can anyone help me?
Material = game.Lighting.Loot:getChildren() Foil = game.workspace:WaitForChild("Foil") while wait() do print("Spawning") wait(2) for i = 1, #Material do if Material[i] and Material[i]:findFirstChild("Foil") then if Foil.Parent ~= game.workspace then Materials = Material[i]["Foil"].Parent:Clone() Materials.Parent = workspace Part = game.Workspace.Part if Part ~= nil then Materials:MoveTo(Part.Position) end end end end end
This is just an exemple:
Childs = { } -- Table function Find() for i, a in pairs(workspace:GetChildren()) do table.insert(Childs, a) end for i, b in pairs(Childs) do if tostring(b) == "lewl" then -- If in the workspace you found an Instance named "lewl" then print("here") -- Say here Childs = { } -- Cleaning the Table else print("Not here") Childs = { } -- Cleaning the Table end end end while true do wait(2) Find() end