superICH3
|
  |
| Joined: 25 May 2010 |
| Total Posts: 4729 |
|
|
| 07 Sep 2016 03:37 PM |
The goal of this chunk of code is to find each model named "Tree" and list them in an array. And when the axe tool comes in contact with one of the hitbox part, which would be a descendant of one of the listed "Tree" parts, it is supposed to set Anchored to false.
It detects the hitbox but doesn't set Anchored to false, and returns an error saying "attempt to index field '?' (a nil value)"
local function getTrees() local trees = {} local treeAmount = 0 for index, child in pairs(workspace:GetChildren()) do if child.Name == "Tree" and child.ClassName == "Model" then table.insert(trees, child) treeAmount = treeAmount + 1 end end
return trees, treeAmount end local trees = getTrees() local treeAmount = getTrees() print(#treeAmount) print(trees[1].timber.trunk.Material)
for i=0,#treeAmount, 1 do if otherPart:IsDescendantOf(trees[i]) and otherPart.Name == "hitbox" and hitting == false then hitting = true wait(0.3) script.Parent.Handle.Sound:Play() trees[i].timber.leaf.Anchored = false trees[i].timber.trunk.Anchored = false end end
|
|
|
| Report Abuse |
|
|
qqtt991
|
  |
| Joined: 14 Dec 2007 |
| Total Posts: 1387 |
|
|
| 07 Sep 2016 04:42 PM |
| ######### is not defined anywhere in the script, also you should do local trees, treeAmount = ########## print(treeAmount) instead of doing local trees = ########## local treeAmount = ########## print(#treeAmount) |
|
|
| Report Abuse |
|
|
qqtt991
|
  |
| Joined: 14 Dec 2007 |
| Total Posts: 1387 |
|
| |
|
superICH3
|
  |
| Joined: 25 May 2010 |
| Total Posts: 4729 |
|
|
| 07 Sep 2016 04:54 PM |
| ##################################### |
|
|
| Report Abuse |
|
|
superICH3
|
  |
| Joined: 25 May 2010 |
| Total Posts: 4729 |
|
|
| 07 Sep 2016 04:54 PM |
| ######### ## in the parameters of the function(that i did not post) |
|
|
| Report Abuse |
|
|
qqtt991
|
  |
| Joined: 14 Dec 2007 |
| Total Posts: 1387 |
|
|
| 07 Sep 2016 04:56 PM |
Well that error usually means you're going out of bounds in an array, and you're not using the return values of that function correctly, so try fixing that first.
|
|
|
| Report Abuse |
|
|
superICH3
|
  |
| Joined: 25 May 2010 |
| Total Posts: 4729 |
|
|
| 07 Sep 2016 05:03 PM |
it must be the array going out of bounds
|
|
|
| Report Abuse |
|
|
superICH3
|
  |
| Joined: 25 May 2010 |
| Total Posts: 4729 |
|
|
| 07 Sep 2016 05:04 PM |
| But I have no idea why it would do that.. #### |
|
|
| Report Abuse |
|
|
|
| 07 Sep 2016 05:04 PM |
put some prints inside to debug it and see what is wrong
usually means you are trying to get some sort of value or index of a value or object but it appears to be nil |
|
|
| Report Abuse |
|
|
superICH3
|
  |
| Joined: 25 May 2010 |
| Total Posts: 4729 |
|
|
| 07 Sep 2016 05:08 PM |
So this doesn't even print, for some reason.. Even though it detects the hitboxTree and only that.
for i=0,treeAmount, 1 do if otherPart:IsDescendantOf(trees[i]) and otherPart.Name == "hitboxTree" and hitting == false then hitting = true wait(0.3) script.Parent.Handle.Sound:Play() print(trees[i].timber.leaf.Material) <--This one!!!!! trees[i].timber.leaf.Anchored = false trees[i].timber.trunk.Anchored = false end end
3,488 |
|
|
| Report Abuse |
|
|
qqtt991
|
  |
| Joined: 14 Dec 2007 |
| Total Posts: 1387 |
|
|
| 07 Sep 2016 05:08 PM |
!!!! I think the problem is here. I think I recall Lua tables start with the index at 1, not 0.
for i=0,#treeAmount, 1 do
|
|
|
| Report Abuse |
|
|
superICH3
|
  |
| Joined: 25 May 2010 |
| Total Posts: 4729 |
|
|
| 07 Sep 2016 05:11 PM |
| I FIXED IT!!!!!! Thank you for your help, everyone! Rap: #### |
|
|
| Report Abuse |
|
|