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)

1 comment
Thanks, but now the function won't return "v" as the players name why?