Hello Developers!
I’m making a board game, in my game. But my problem is, it said attempt to index nil with 'FindFirstChild'. I put a comment in the line script -- Error is here so you would know where it is. Thanks for the help!
My script:
local EastIsAvailable = false
local WestIsAvailable = false
local NorthIsAvailable = false
if player.Name == script.Parent.PlayerUser.Value the
for _, f in pairs(Board.Parent.Checks:GetChildren()) do
for _, s in pairs(f:GetChildren()) do
if s.Value == Board.Name.."Spy2" then
local s_ToInteger = tonumber(script.Parent.StringToNumber:FindFirstChild(s.Name).Value)
local CheckEast = s_ToInteger + 1
local CheckWest = s_ToInteger - 1
local North = table.find(alphabet, string.lower(f.Name))
print("North prev int: "..North)
local _North = North - 1
print("North next int: ".._North)
local CheckNorth = alphabet[_North]
print("East int: "..CheckEast)
print("West int: "..CheckWest)
print("North letter: "..CheckNorth)
delay(0.1, function()
if Board.Parent.Checks:FindFirstChild(CheckNorth):FindFirstChild(s.Name) ~= "" then -- Error Here
NorthIsAvailable = true
else
NorthIsAvailable = false
end
if Board.Parent.Checks:FindFirstChild(f.Name):FindFirstChild(CheckEast).Value ~= "" then -- Maybe also here?
EastIsAvailable = true
else
EastIsAvailable = false
end
if Board.Parent.Checks:FindFirstChild(f.Name):FindFirstChild(CheckWest).Value ~= "" then -- and here??
WestIsAvailable = true
else
WestIsAvailable = false
end
end)
end
end
end
This problem is most likely, because there isn’t a variable ‘CheckNorth’ or it doesn’t exist in Board.Parent.Checks. If the name of the needed object is ‘CheckNorth’ try it like this:
I think I know the issue now. If you keep counting _North down, eventually it will be 0. So CheckNorth will be nil, since 0 isn’t a index of the table. Try adding this line, before the delay function:
local EastIsAvailable = false
local WestIsAvailable = false
local NorthIsAvailable = false
if player.Name == script.Parent.PlayerUser.Value then
for _, f in pairs(Board.Parent.Checks:GetChildren()) do
for _, s in pairs(f:GetChildren()) do
if s.Value == Board.Name.."Spy2" then
local s_ToInteger = tonumber(script.Parent.StringToNumber:FindFirstChild(s.Name).Value)
local CheckEast = s_ToInteger + 1
local CheckWest = s_ToInteger - 1
local North = table.find(alphabet, string.lower(f.Name))
print("North prev int: "..North)
local _North = North - 1
print("North next int: ".._North)
local CheckNorth = alphabet[_North]
print("East int: "..CheckEast)
print("West int: "..CheckWest)
print("North letter: "..CheckNorth)
delay(0.1, function()
if Board.Parent.Checks:FindFirstChild(CheckNorth):FindFirstChild(s.Name) ~= "" then -- Error Here
NorthIsAvailable = true
else
NorthIsAvailable = false
end
if Board.Parent.Checks:FindFirstChild(f.Name):FindFirstChild(CheckEast).Value ~= "" then -- Maybe also here?
EastIsAvailable = true
else
EastIsAvailable = false
end
if Board.Parent.Checks:FindFirstChild(f.Name):FindFirstChild(CheckWest).Value ~= "" then -- and here??
WestIsAvailable = true
else
WestIsAvailable = false
end
end)
end
end
end
end
if player.Name == script.Parent.PlayerUser.Value the
Missing “n” at end, also missing an end statement at the end of the script.
“Board.Parent.Checks” this however must be nil, so make sure the references are correct.