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 check if a part is missing?

Trying to make a GUI detect if a certain brick is missing but I have no idea on how do I make a script check if a certain brick is not there.

Example:

if 
-- command that checks if it is not there with a certain name
then script.Parent.Frame.Visible = false

New to vehicle /gun scripting.

3 answers

Use the FindFirstChild method to return the object if it exists.

if not workspace.Model:FindFirstChild("PartName") then
script.Parent.Frame.Visible = false
end

1 comment

0

Thanks DigitalVeer!

Make a variable using FindFirstChild.

For example:

Part = Part'sParent:FindFirstChild("PartName")

Then, do an if/then statement, to see if it exists:

if Part == nil then
script.Parent.Frame.Visible = false

Add them all together, and you get this:

Part = Part'sParent:FindFirstChild("PartNameHere")
if Part == nil then
script.Parent.Frame.Visible = false

NOTE: Replace (Part'sParent) with the location of the part's parent, and replace "PartNameHere with the name of the part you want to check that exists or not

Please accept my answer if this helped!

1 comment

0

The script works but the problem is that it doesnt turn visible/invisible while im still on the seat and only works when I re-sit.

You need to write something like this:

local PlayerGui = game.Players.LocalPlayer:WaitForChild('PlayerGui')


local Thing = game.Workspace:FindFirstChild('[ Part Name ]')


if Thing == nil then


	PlayerGui.[ Gui ].Frame.Visible = false


end

Just like that.

1 comment

0

OH, IT WAS 6 YEARS AGO...

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