I'll be using and if then
and I want to see if an instance is in a part and if it is, I want it to be replaced with a new instance. Help?
As RedCombee has answered, why not use the FindFirstChild Method? If the FindFirstChild
method finds the Child, then it'll return true, elseif could not find the Child, then it'll return nil, here's an example of what I mean;
local child = game.Workspace:FindFirstChild("Child") --Here's 'FindFirstChild'; this will check to see if 'Child' is existant in the Workspace if child then --If 'child' is existant print("Child found!") --It'll print this in the Output else --Elseif 'child' is not existant then print("Child not found!") --It'll print this in the Output end
Or, you could do FindFirstChild("Child",true)
, that will check the game, even if 'Child' is in a 'Model' type instance, it'll still beable to tell if existant or not, here's an example of what I mean;
Game Workspace Model Child
Now, let's use the FindFirstChild("Child",true)
method;
local child = game.Workspace:FindFirstChild("Child",true) if child then --If 'child' is existant print("Child found!") --It'll print this in the Output else --Elseif 'child' is not existant then print("Child not found!") --It'll print this in the Output end
And, as you'll see, even though it's not exactly in the 'Workspace', it'll still beable to find it when you add ,true
in with the FindFirstChild
method.
Hope this helped!
If part:FindFirstChild("NameOfInstance") then -- This will search through the part for an instance.