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

how do you check if a part in the character exists?

Asked by 4 years ago

I am trying to check if a part in the character exists, but if i do this script below it does not work. Why does this script not work? if player.Character.Glasses1 then print("your mom") end

3 answers

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

To ensure your part is located, we will design a function that will use a rigorous search, so to speak.

Firstly, we'll allow this function to use :WaitForChild() to account for Client latency. We'll allow a timeout of five seconds—the internal leniency window before a yield-warn—to locate the Instance. If this limit is surpassed while no Instance is found, we'll engage a .ChildAdded signal to listen for new Instances, and to check whether said newly added Instance is the one we were originally looking for.

LocalScript; StarterCharacterScripts.

01--###----------[[SERVICES]]----------###--
02local Player = game:GetService("Players")
03 
04 
05 
06--###----------[[VARAIBLES]]----------###--
07local Character = Player.Character or Player.CharacterAdded:Wait()
08 
09local ChildAdded;
10 
11 
12 
13--###----------[[FUNCTIONS]]----------###--
14local function CheckForPart()
15    local Part = Character:WaitForChild("Glasses1", 1)
View all 33 lines...
0
what does the semi colon at the end of the child added variable mean Oliverplays100 -3 — 4y
0
The semi-colon has no actual significance to the Lua compiler. It can act as a line-break though. In this case, since I am only declaring a variable, I optionally chose to do this as it signifies that there is nothing left needed on that line. Ziffixture 6913 — 4y
0
what does the semi colon at the end of the child added variable mean Oliverplays100 -3 — 4y
0
what is the, "if (ChildAdded)" checking for, and why do you put the command, "ChildAdded:Disconnect()" what does it do? Oliverplays100 -3 — 4y
0
This all links to the proper management of the RBXScriptConnection. Ziffixture 6913 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

You can use a function: ~~~~~~~~~~~~~~~~~ Instance:FindFirstChild("NameHere") ~~~~~~~~~~~~~~~~~

Log in to vote
-1
Answered by 4 years ago
1local Players = game:GetService("Players")
2Players.Character:FindFirstChild("whatever the name is")

Answer this question