Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How could I fix this? attempt to call method 'GetChildren' (a nil value)

Asked by 10 years ago

I got an error saying:

Workspace.Script:4: attempt to call method 'GetChildren' (a nil value)

19:41:56.037 - Stack Begin

19:41:56.037 - Script 'Workspace.Script', Line 4 - global FindFirstInTable

I don't get why I got this error,why did I get it?

01PlayerWithTools = {"Zombomafoo","Player1"}
02--------------------------------------------------
03function FindFirstInTable(Table,String)
04    for _,v in pairs (Table:GetChildren()) do
05        if v == String then
06            return v,true
07        else
08            return false
09        end
10    end
11end
12--------------------------------------------------
13game.Players.PlayerAdded:connect(function(Player)
14    Player.CharacterAdded:connect(function(Character)
15----------------------------------------------------
View all 24 lines...

--Fixed Script--

01PlayerWithTools = {"Zombomafoo","Player1"}
02--------------------------------------------------
03function FindFirstInTable(Table,String)
04    for _,v in pairs (Table) do
05        if v == String then
06            return v,true
07        else
08            return false
09        end
10    end
11end
12--------------------------------------------------
13game.Players.PlayerAdded:connect(function(Player)
14    Player.CharacterAdded:connect(function(Character)
15----------------------------------------------------
View all 24 lines...

1 answer

Log in to vote
1
Answered by
User#2 0
10 years ago

Tables do not have a FindFirstChild method by default.

The FindFirstChild method is only a method of objects, and it returns a table.

You're very close, although you have added :GetChildren() where it is not needed.

1for _, v in pairs(Table) do
2    -- Do what you would like
3end
0
Thanks, but now the function won't return  "v"  as the players name why? kevinnight45 550 — 10y
Ad

Answer this question