Help with detecting if an object is in workspace

Hi everyone! I’m trying to create a local script that does something when a bunch of objects are in workspace.
I’ve tried the following script, but it doesn’t worked.

if workspace.Obj1 and workspace.Obj2 and workspace.Obj3 == true then
--the rest of the script
end

(There’s no problem that I’m using a local script, I’m only going to interact with the player gui)

If Obj1.Parent.Name = “Workspace” then
—Run the rest of the script
End

You could also make a table with all of the objects and loop through it with this.

1 Like

If you want to search for something specific:

if workspace:FindFirstChild("Obj") then -- name of the object in question
	-- Code
end

For something to happen when there are more than X number of instances that have workspace as their parent:

if #workspace:GetChildren() > 10 then -- replace 10 with the number
    -- Code
end

For something to happen when there are more than X number of instances that are descendants of workspace:

if #workspace:GetDescendants() > 10 then -- replace 10 with the number
	-- Code
end

Sources: FindFirstChild, GetChildren, GetDescendants, Measure a table.

2 Likes