1
Attempt to index a nil value Fixed! on 2/6/2012, 7:00 am
Here is a peculiar set of functions I created for making code that will almost never break in game. Basically it works by searching up the object you are looking for every time with a series of gates to make sure the code doesn't error and break. Here is how to use it:
1. Paste this set of code to the beginning of your script:
2. Search for a value starting at game (as in game.Workspace) like this:
or starting at another part like this:
3. Run this function every so often to get rid of the extra debugs
Most average scripters won't need this, but for you few who have huge complex scripts, this could be really helpful in making your place impervious to breaking.
1. Paste this set of code to the beginning of your script:
- Code:
debugIndex = {}
function temp(type)
local debug = Instance.new(type)
debug.Parent = Workspace
debug.Name = "debug " .. script.Name .. " " .. type
debugIndex[#debugIndex + 1] = debug
return debug
end
function find(path, type, start)
if start == nil then start = game
end
local debug = temp(type)
local Locate = start
local a = 1
for i = 1, #path do
local temp = Locate:findFirstChild(path[i])
if temp == nil then
print("Failed to find " .. path[#path])
return debug
else
Locate = temp
end
a = i
end
if a == #path then
debug:Remove()
return Locate
else
print("Failed to find " .. path[#path])
return debug
end
end
function cleardebug()
for i = 1, #debugIndex do
debugIndex[i]:Remove()
end
end
2. Search for a value starting at game (as in game.Workspace) like this:
- Code:
find({"Workspace","Brick"},"Part")
or starting at another part like this:
- Code:
find({"Head","Face"},"Decal",Player)
3. Run this function every so often to get rid of the extra debugs
- Code:
cleardebug()
Most average scripters won't need this, but for you few who have huge complex scripts, this could be really helpful in making your place impervious to breaking.

