Advertisement
Majd07

ROBLOX Thread - how to detect objects with code

Dec 31st, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. Hello robloxians!
  2.  
  3. you probably are searching for a way to test if things exist and some people have ideas on how to do so and they don't work.
  4.  
  5. well, I made a function to test for objects, their className, and any other property.
  6.  
  7.  
  8.  
  9.  
  10. here is the code:
  11.  
  12. --Name
  13.  
  14. _G.exist = function(location, item)
  15. local children = location:GetChildren()
  16. local Return = nil
  17. for i = 1, #children do
  18. if children[i].Name == item then
  19. Return = true
  20. end
  21. if i == #children then
  22. if not Return == true then
  23. Return = false
  24. end
  25. end
  26. end
  27. return Return
  28. end
  29.  
  30. --className
  31.  
  32. _G.existsOfClassName = function(location, item)
  33. local children = location:GetChildren()
  34. local Return = nil
  35. for i = 1, #children do
  36. if children[i].Name == item then
  37. Return = true
  38. end
  39. if i == #children then
  40. if not Return == true then
  41. Return = false
  42. end
  43. end
  44. end
  45. return Return
  46. end
  47.  
  48. --Any property
  49.  
  50. _G.existsOfProperty = function(location, typeValue, typeName)
  51. local children = location:GetChildren()
  52. local Return = nil
  53. for i = 1, #children do
  54. if children[i][typeName] == typeValue then
  55. Return = true
  56. end
  57. if i == #children then
  58. if not Return == true then
  59. Return = false
  60. end
  61. end
  62. end
  63. return Return
  64. end
  65.  
  66. --[[And remember:
  67. that the property for the existOfProperty function's 3rd parameter (the typeName parameter) has to be
  68. in quotes.
  69. ,
  70. to use _G. [ function name ] () Instead of [ function name ] () for example:
  71. _G.existsOfClassName
  72. Instead of:
  73. existsOfClassName.
  74. ,
  75. that you only have to put all this code in a script and then you don't have to put it in every script
  76. you made just use _G. [ function name ] .
  77. ]]
  78.  
  79. .
  80.  
  81. If there are any errors or this code didn't work please reply that on this thread
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement