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

How do you check if something in workspace isn't there?

Asked by
Yeevivor4 155
9 years ago

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

2 answers

Log in to vote
2
Answered by 9 years ago

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
Ad
Log in to vote
-1
Answered by 9 years ago

This has been asked before. (Right)

0
No, it's a different question now. Yeevivor4 155 — 9y
0
Oh Ewarr1011 0 — 9y

Answer this question