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: nil

Previous Thread :: Next Thread 
dog456pop248 is not online. dog456pop248
Joined: 24 Aug 2008
Total Posts: 3977
14 Mar 2013 09:14 PM
I have a script that shatters a rock into smaller pieces when it hits the ground. The 'pieces' are welded inside the rock (Each piece of rock has a bool value called Broken, FYI) and the part that holds the rock together, "Main", is parented to lighting (when you use :destroy() and you rewind, it is irreversible.) When the rock hits the base plate I get the error "Broken is not a valid member of part".. I want the script to execute when Broken returns nil or true, but instead it errors. This is getting extremely frustrating.

function RockBreak(p)
if p.Broken == nil or p.Broken.Value == true then
game.Workspace.Rock.Main.Parent = game.Lighting
script.Parent:BreakJoints()
for _,v in pairs(script.Parent:GetChildren()) do
if v:IsA("BasePart") then
v.Broken.Value = true
end
end
end
end

script.Parent.Main.Touched:connect(RockBreak)

>Broken is not a valid member of Part
>Script "Workspace.Rock.Script", Line 2
>stack end
>Disconnected event because of exception
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
14 Mar 2013 09:19 PM
Try:


    if p:FindFirstChild("Broken") and p.Broken.Value then

¤ ¤ † K M <( •д• )> X D † ¤ ¤
Report Abuse
dog456pop248 is not online. dog456pop248
Joined: 24 Aug 2008
Total Posts: 3977
14 Mar 2013 09:24 PM
That bit of the if statement works fine.
When Broken returns nil, it just says "Broken is a valid member of blah blah etc etc" it doesn't use the if statement.
Which really wants me to punch somebody
what the heck lua
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
14 Mar 2013 09:27 PM
No, that part would make it error. If you did that, and Broken wasn't there, it would error, like it did for you. FindFirstChild should make it work fine even if Broken isn't there.

¤ ¤ † K M <( •д• )> X D † ¤ ¤
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
14 Mar 2013 09:28 PM
Oh, I didn't see the or operator. What are the conditions you want?

¤ ¤ † K M <( •д• )> X D † ¤ ¤
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
14 Mar 2013 09:29 PM
Are you saying you want the code to execute if broken is either true or false? If it's nil, the code would error.

¤ ¤ † K M <( •д• )> X D † ¤ ¤
Report Abuse
dog456pop248 is not online. dog456pop248
Joined: 24 Aug 2008
Total Posts: 3977
14 Mar 2013 09:30 PM
Well, I can fix this problem by copying the "Broken" bool into every part I want it to expload on, or I can have it check to see if "Broken" = nil
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
14 Mar 2013 09:32 PM
If I'm correct, you want the code to execute if there's a bool value called "Broken" inside of the part, whether Broken's value is either true or false. If so, just check if Broken is there, using FindFirstChild.

¤ ¤ † K M <( •д• )> X D † ¤ ¤
Report Abuse
dog456pop248 is not online. dog456pop248
Joined: 24 Aug 2008
Total Posts: 3977
14 Mar 2013 09:50 PM
Incorrect.
I want it to check if the bool value Broken is either nil or true. So the rock will break on broken rock shards, or normal bricks.
Report Abuse
dog456pop248 is not online. dog456pop248
Joined: 24 Aug 2008
Total Posts: 3977
14 Mar 2013 09:51 PM
The reason there's a bool value in each rock shard is because the rock would break on itself without any sort of regulation. (The script is fired by .Touch, and the rock shards are welded inside of the main rock)
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
14 Mar 2013 10:22 PM
Then you would just do:


    if not p:FindFirstChild( "Broken" ) or ( p:FindFirstChild( "Broken" ) and p.Broken.Value ) then

¤ ¤ † K M <( •д• )> X D † ¤ ¤
Report Abuse
dog456pop248 is not online. dog456pop248
Joined: 24 Aug 2008
Total Posts: 3977
14 Mar 2013 10:28 PM
I didn't think you could use if x and if not x for checking if an object is nil.
Thanks!
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