Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

1 comment

0

thats fine, but you could also make use of the .Changed event

2 answers

✓ Accepted answer

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.

1 comment

0

thank you so much

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

2 comments

0

his code means the same thing

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

This discussion is preserved as it was. New answers, comments, and votes are closed.