MrSet
|
  |
| Joined: 28 Apr 2012 |
| Total Posts: 68 |
|
|
| 03 Aug 2014 01:12 PM |
| for example lets say I had a part called brick in workspace how do i confirm i have a part in workspace named brick? |
|
|
| Report Abuse |
|
|
CaptLlama
|
  |
| Joined: 02 Nov 2013 |
| Total Posts: 1914 |
|
|
| 03 Aug 2014 01:14 PM |
if Brick == true then print("It exists.") end |
|
|
| Report Abuse |
|
|
|
| 03 Aug 2014 01:14 PM |
if workspace:FindFirstChild("Brick") then end |
|
|
| Report Abuse |
|
|
CaptLlama
|
  |
| Joined: 02 Nov 2013 |
| Total Posts: 1914 |
|
|
| 03 Aug 2014 01:15 PM |
if game.Workspace.Brick*
or use a variable |
|
|
| Report Abuse |
|
|
|
| 03 Aug 2014 01:15 PM |
| capt, with if statements you don't need the "== true" |
|
|
| Report Abuse |
|
|
CaptLlama
|
  |
| Joined: 02 Nov 2013 |
| Total Posts: 1914 |
|
|
| 03 Aug 2014 01:16 PM |
| actually I think im terribly wrong, don't listen to me lol |
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 03 Aug 2014 01:17 PM |
if workspace:FindFirstChild("Brick") ~= nil then --exists end |
|
|
| Report Abuse |
|
|
DevUndead
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 558 |
|
|
| 03 Aug 2014 01:18 PM |
If game.Workspace:GetChildren("Brickname") then --code here End |
|
|
| Report Abuse |
|
|
|
| 03 Aug 2014 01:19 PM |
"If game.Workspace:GetChildren("Brickname") then"
you can do that...? |
|
|
| Report Abuse |
|
|
DevUndead
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 558 |
|
|
| 03 Aug 2014 01:25 PM |
| Yes, because if it finds it than that becomes a book of true and goes throught the function. |
|
|
| Report Abuse |
|
|
|
| 03 Aug 2014 01:28 PM |
| That script always ends up true regardless of whether it can find the part or not, it seems |
|
|
| Report Abuse |
|
|
DevUndead
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 558 |
|
|
| 03 Aug 2014 01:34 PM |
| Put a == true that May solve it |
|
|
| Report Abuse |
|
|
Kyuro
|
  |
| Joined: 03 Sep 2012 |
| Total Posts: 5800 |
|
|
| 03 Aug 2014 01:36 PM |
if game.Workspace.Brick ~= nil then -- code end |
|
|
| Report Abuse |
|
|
Kingmouli
|
  |
| Joined: 28 Sep 2012 |
| Total Posts: 1292 |
|
|
| 03 Aug 2014 02:03 PM |
if game.Workspace:FindFirstChild("Brick") then print("Something in Workspace is named Brick") end |
|
|
| Report Abuse |
|
|
|
| 03 Aug 2014 02:04 PM |
"if game.Workspace.Brick ~= nil then -- code end"
FindFirstChild is superior! |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 03 Aug 2014 03:03 PM |
| Everyone who didn't use FindFirstChild is wrong. |
|
|
| Report Abuse |
|
|
DevUndead
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 558 |
|
|
| 03 Aug 2014 04:44 PM |
| What if there are multiple children with the same object name? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 03 Aug 2014 04:48 PM |
| It gets the first one, as the function implies: "find FIRST child" |
|
|
| Report Abuse |
|
|
DevUndead
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 558 |
|
|
| 03 Aug 2014 04:49 PM |
| It's not wrong per say because it still gives the correct output, it just is a different way of getting the value. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 03 Aug 2014 04:51 PM |
No, your way is wrong. The GetChildren function doesn't care about arguments you give it, all it does is return a table of every direct descendant of the object you called it on. If there are no children it will still return an empty table which is still not equal to nil. So no matter what you do, the conditional statement will be true. |
|
|
| Report Abuse |
|
|
DevUndead
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 558 |
|
| |
|
Snej1
|
  |
| Joined: 25 Jun 2008 |
| Total Posts: 809 |
|
|
| 03 Aug 2014 05:38 PM |
If you happen to have several different objects (different classnames) with the same name you'll have to do something like this:
function FindObject(parent, name, class) for _, v in pairs(parent:GetChildren()) do if (v.Name == name) and (v.ClassName == class) then return v end end end |
|
|
| Report Abuse |
|
|
|
| 03 Aug 2014 05:42 PM |
for i,v in pairs(game.Workspace:GetChildren()) do if v.Name == "Brick" then print'It's Here Every One!!!' end end |
|
|
| Report Abuse |
|
|
|
| 03 Aug 2014 05:44 PM |
if game.workspace:findFirstChild("Brick") then print("brick exist") end
else
print("no")
Previous username LordDestroyerChaos/TehChaosGuest |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 03 Aug 2014 05:45 PM |
| That wouldn't work, the end should be after the print("no"), not before the else. |
|
|
| Report Abuse |
|
|