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 » Scripters
Home Search
 

Re: A nil value?

Previous Thread :: Next Thread 
superICH3 is not online. 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 is not online. 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 is not online. qqtt991
Joined: 14 Dec 2007
Total Posts: 1387
07 Sep 2016 04:43 PM
FFS.

past
ebin.
com/
EvCtSs0H


Report Abuse
superICH3 is not online. superICH3
Joined: 25 May 2010
Total Posts: 4729
07 Sep 2016 04:54 PM
#####################################
Report Abuse
superICH3 is not online. 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 is not online. 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 is not online. 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 is not online. 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
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
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 is not online. 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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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