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

How do I check if a part is missing?

Asked by 10 years ago

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:

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

New to vehicle /gun scripting.

3 answers

Log in to vote
0
Answered by 10 years ago

Use the FindFirstChildmethod to return the object if it exists.

1if not workspace.Model:FindFirstChild("PartName") then
2script.Parent.Frame.Visible = false
3end
0
Thanks DigitalVeer! VeteranHawk 5 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

Make a variable using FindFirstChild.

For example:

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

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

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

Add them all together, and you get this:

1Part = Part'sParent:FindFirstChild("PartNameHere")
2if Part == nil then
3script.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!

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. VeteranHawk 5 — 10y
Log in to vote
0
Answered by 4 years ago

You need to write something like this:

01local PlayerGui = game.Players.LocalPlayer:WaitForChild('PlayerGui')
02 
03 
04local Thing = game.Workspace:FindFirstChild('[ Part Name ]')
05 
06 
07if Thing == nil then
08 
09 
10    PlayerGui.[ Gui ].Frame.Visible = false
11 
12 
13end

Just like that.

0
OH, IT WAS 6 YEARS AGO... TinkyWinkyDev 6 — 4y

Answer this question