generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Help me fix this, please.

Previous Thread :: Next Thread 
Perci1 is not online. 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 is not online. 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 is not online. 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
CowBeatsMinecraft is not online. CowBeatsMinecraft
Joined: 23 Nov 2010
Total Posts: 649
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
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
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 is not online. 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
CodeTheorem is not online. CodeTheorem
Joined: 03 Jun 2009
Total Posts: 2771
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
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
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
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
10 Mar 2014 10:41 AM
Good job, I never even picked up on that!
Report Abuse
Perci1 is not online. Perci1
Joined: 24 Jan 2011
Total Posts: 1027
10 Mar 2014 02:55 PM
Thanks, Code
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image