Perci1
|
  |
| Joined: 24 Jan 2011 |
| Total Posts: 1027 |
|
|
| 10 Mar 2014 09:13 AM |
function getBob() for i,v in pairs(Workspace:GetChildren()) do if v.Name == "bob" then return v else return false end end end
print(getBob())
The problem is, getBob is always returning false, even when I deliberately name a brick "bob". Why is this? |
|
|
| Report Abuse |
|
|
Robotized
|
  |
| Joined: 14 Feb 2010 |
| Total Posts: 167 |
|
|
| 10 Mar 2014 09:16 AM |
if you did variable.Name="bob" then it wont work. don't ask me why, that happened to me too. to rename your brick using a script try this:
b={}
table.insert(b,variable) print(b[1]) b[1].Name="whatever you like" print(b[1])
*note that variable in this case is what indexes your brick |
|
|
| Report Abuse |
|
|
Perci1
|
  |
| Joined: 24 Jan 2011 |
| Total Posts: 1027 |
|
|
| 10 Mar 2014 09:36 AM |
| I'm naming the brick manually. The problem is that it is never finding the brick's name to be equal to bob, so it immediately goes to the else and the function returns false. |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2014 09:40 AM |
the function is not connected to anything, you have to connect the function to another bit of code, im not sure what but, you know like the function onClick() ~~~~~ end
script.Parent.MouseButton1Click:connect(onClick) |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2014 09:49 AM |
part = Workspace:GetChildren() function getBob() for i,#part do if part[i].Name == "bob" then print(v) else return false end end end
getBob()
--Just my lame attempt at trying to fix it, but still see if it works... |
|
|
| Report Abuse |
|
|
Perci1
|
  |
| Joined: 24 Jan 2011 |
| Total Posts: 1027 |
|
|
| 10 Mar 2014 09:59 AM |
@war, You have a simple error in there, but that is not what I'm trying to do. I don't want to print(v), I want to return it. That way the function getBob() basically turns into a variable.
@Cow, No, I do not want it connected to an event. |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2014 10:30 AM |
The problem is, if you go through, and the first one isn't "bob", then you'll return false! Returning anything immediately exits all loops and functions!! You need to go through the WHOLE LOOP, and if you exit the loop normally, without returning, THEN return false. Like this:
function getBob() for i,v in pairs(Workspace:GetChildren()) do if v.Name == "bob" then return v end end return false end
print(getBob()) |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2014 10:33 AM |
part = Workspace:GetChildren() function getBob() for i,#part do if part[i].Name == "bob" then return part[i].Name else return false end end end
print(getBob())
Yes I found my error... lol. Try that? |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2014 10:41 AM |
| Good job, I never even picked up on that! |
|
|
| Report Abuse |
|
|
Perci1
|
  |
| Joined: 24 Jan 2011 |
| Total Posts: 1027 |
|
| |
|