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?
PlayerWithTools = {"Zombomafoo","Player1"} -------------------------------------------------- function FindFirstInTable(Table,String) for _,v in pairs (Table:GetChildren()) do if v == String then return v,true else return false end end end -------------------------------------------------- game.Players.PlayerAdded:connect(function(Player) Player.CharacterAdded:connect(function(Character) ---------------------------------------------------- Player = FindFirstInTable(PlayerWithTools,Player.Name) if Player then for _,Tools in pairs (game.ServerStorage:GetChildren()) do ClonedTools = Tools:Clone() ClonedTools.Parent = Player.Backpack end end end) end)
--Fixed Script--
PlayerWithTools = {"Zombomafoo","Player1"} -------------------------------------------------- function FindFirstInTable(Table,String) for _,v in pairs (Table) do if v == String then return v,true else return false end end end -------------------------------------------------- game.Players.PlayerAdded:connect(function(Player) Player.CharacterAdded:connect(function(Character) ---------------------------------------------------- Player = FindFirstInTable(PlayerWithTools,Player.Name) if Player then for _,Tools in pairs (game.ServerStorage:GetChildren()) do ClonedTools = Tools:Clone() ClonedTools.Parent = Player.Backpack end end end) end)
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.
for _, v in pairs(Table) do -- Do what you would like end