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
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.
--###----------[[SERVICES]]----------###-- local Player = game:GetService("Players") --###----------[[VARAIBLES]]----------###-- local Character = Player.Character or Player.CharacterAdded:Wait() local ChildAdded; --###----------[[FUNCTIONS]]----------###-- local function CheckForPart() local Part = Character:WaitForChild("Glasses1", 1) if (Part) then --------------- --// Action for when the part is located. --------------- if (ChildAdded) then ChildAdded:Disconnect() end else if (not ChildAdded) then ChildAdded = Character.ChildAdded:Connect(CheckForPart) end end end --###----------[[LOGIC]]----------###-- CheckForPart()
You can use a function: ~~~~~~~~~~~~~~~~~ Instance:FindFirstChild("NameHere") ~~~~~~~~~~~~~~~~~
local Players = game:GetService("Players") Players.Character:FindFirstChild("whatever the name is")