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: How do i make a script determine rather a part exist

Previous Thread :: Next Thread 
MrSet is not online. 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 is not online. CaptLlama
Joined: 02 Nov 2013
Total Posts: 1914
03 Aug 2014 01:14 PM
if Brick == true then
print("It exists.")
end
Report Abuse
GamesKeith is not online. GamesKeith
Joined: 28 Jul 2014
Total Posts: 2261
03 Aug 2014 01:14 PM
if workspace:FindFirstChild("Brick") then
end
Report Abuse
CaptLlama is not online. CaptLlama
Joined: 02 Nov 2013
Total Posts: 1914
03 Aug 2014 01:15 PM
if game.Workspace.Brick*

or use a variable
Report Abuse
GamesKeith is not online. GamesKeith
Joined: 28 Jul 2014
Total Posts: 2261
03 Aug 2014 01:15 PM
capt, with if statements you don't need the "== true"
Report Abuse
CaptLlama is not online. 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 is not online. 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 is not online. 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
GamesKeith is not online. GamesKeith
Joined: 28 Jul 2014
Total Posts: 2261
03 Aug 2014 01:19 PM
"If game.Workspace:GetChildren("Brickname") then"

you can do that...?
Report Abuse
DevUndead is not online. 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
DarkspineDP is not online. DarkspineDP
Joined: 02 May 2009
Total Posts: 67
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 is not online. DevUndead
Joined: 24 Jul 2014
Total Posts: 558
03 Aug 2014 01:34 PM
Put a == true that May solve it
Report Abuse
Kyuro is not online. 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 is not online. 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
GamesKeith is not online. GamesKeith
Joined: 28 Jul 2014
Total Posts: 2261
03 Aug 2014 02:04 PM
"if game.Workspace.Brick ~= nil then
-- code
end"

FindFirstChild is superior!
Report Abuse
cntkillme is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. DevUndead
Joined: 24 Jul 2014
Total Posts: 558
03 Aug 2014 05:02 PM
Mkay m8 sure
Report Abuse
Snej1 is not online. 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
GloriusBlade is not online. GloriusBlade
Joined: 01 Nov 2013
Total Posts: 82
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
TheCommanderGuest is not online. TheCommanderGuest
Joined: 03 Jun 2012
Total Posts: 11861
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 is not online. 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
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