|
| 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 |
|
|
|
| 14 Mar 2013 09:19 PM |
Try:
if p:FindFirstChild("Broken") and p.Broken.Value then
¤ ¤ † K M <( •д• )> X D † ¤ ¤
|
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|