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

How to Detect if a block does exists or not?

Asked by 4 years ago

So Im trying to make a script that if lets say... a Part does not exist then it would print out (Part no Exist)

this was the script that I was just playing around with.

if workspace.Part then
    print("Good!")
else
    print("Bad!")
end

But the Output only says

Part is not a valid member of Workspace

Any tips?

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

This is actually quite simple. Here's how:

if workspace:FindFirstChild("Part") then -- Detects if a part named Part is actually in workspace and detects if its nil or not
    print("Good!")
else
    print("Bad!")
end

You can read more on :FindFirstChild() here. Please accept this answer if this helped!

0
Oh yey, How did I not think of doing this? Anyways Thanks a Bunch! roblox136393 32 — 4y
0
No problem! Can you please accept this answer then? Tyler090130 619 — 4y
0
6 months of coding and still don't know how to check if a block exists, Oof roblox136393 32 — 4y
Ad

Answer this question