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

How do I detect if an object is in the workspace?

I tried to do

if workspace.Part then print("1") else instance.new("Part").Parent = workspace end

it said Part isn't a member of workspace

2 answers

If you know the part is either there or isn't there

local Part = workspace:FindFirstChild("PartName")

Or, if you want it as soon as it appears, and it's certain to appear:

local Part = workspace:WaitForChild("PartName")
if Part then
	...
end
  • To find if the part exists, use:
if workspace:FindFirstChild("Part") then
  • To find if the part does not exists, use:
if workspace:FindFirstChild("Part") == nil then
  • Here's a fix to your script.
if workspace:FindFirstChild("Part") then
print("1")
end
if workspace:FindFirstChild("Part") == nil then
Instance.new("Part").Parent = game.Workspace
end

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