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

How to check if an object exists in a loop? [SOLVED]

Asked by 5 years ago
Edited 5 years ago

I want to know how to make a while true function to see if an object still exist. If the object exists, then it keeps running. I thought of this but it was kinda wierd.

while game.Workspace:FindFirstChild("Arrow") do

end
0
thats fine, but you could also make use of the .Changed event Gey4Jesus69 2705 — 5y

2 answers

Log in to vote
0
Answered by
yHasteeD 1819 Moderation Voter
5 years ago
Edited 5 years ago

Its simple, start the loop and use if ...:FindFirstChild(...) then

Here is a example:

while true do -- Start a loop (Do not use while wait() do, its not a good way.)
    if workspace:FindFirstChild("ITEM") then -- Item location
        -- Your code here.
    else
        break -- End loop if object not found
    end
    wait(0.3) -- For no bugs / lag in game
end

But is better use .Changed

Hope it helped :)

Errors? tell-me on comments.

Wiki pages:

while loop

break

FindFirstChild

Changed

Solved your problems? put [SOLVED] in title or accept a answer.
0
thank you so much superbolt999 36 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

While true do wait() if game.Workspace.Part ~= nil then --Checks if the part is there ' --your code goes else --if the part is not there break --the loop will break end end

0
his code means the same thing Gey4Jesus69 2705 — 5y
0
This is incorrect, use :FindFirstChild() and if part does not exist return a error. How to format answers/questions: https://forum.scriptinghelpers.org/topic/82/how-to-format-questions-answers-on-the-main-site yHasteeD 1819 — 5y

Answer this question