This script won't do anything even when the right player enters (Doesn't work in solo also)and i'm guessing its because of line 3. Oh,and how could I fix it?
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)
I think I got it to work, but Roblox is down, so I couldn't test it. I explained your mistakes in the comments.
PlayerWithTools = {"Zombomafoo","Player1"} -------------------------------------------------- function FindFirstInTable(Table,String) for _,v in pairs (Table) do if v == String then return v,true end end return false --The other guy was right about this; it was returning false prematurely. end -------------------------------------------------- game.Players.PlayerAdded:connect(function(Player) Player.CharacterAdded:connect(function(Character) PlayerMatch = FindFirstInTable(PlayerWithTools,Player.Name) --This was originally replacing your Player variable with the string returned from FindFirstInTable. Further down, it was attempting to clone the tools into the string rather than the player. if PlayerMatch then for _,Tools in pairs(game.ServerStorage:GetChildren()) do ClonedTools = Tools:Clone() ClonedTools.Parent = Player.Backpack end end end) end)
I see your problem, after the first time a person doesn't meet the requirements it returns false which causes it to return false prematurely.
PlayerWithTools = {"Zombomafoo","Player1"} -------------------------------------------------- function FindFirstInTable(Table,String) for _,v in pairs (Table) do if v == String then return v,true end end return false -- Outside of the for loop should return false, so it can iterate through the table. end -------------------------------------------------- game.Players.PlayerAdded:connect(function(Player) Player.CharacterAdded:connect(function(Character) ---------------------------------------------------- PlayerMatch = FindFirstInTable(PlayerWithTools,Player.Name) -- Thanks 2eggnog for pointing this out, I didn't even notice. if PlayerMatch then for _,Tools in pairs (game.ServerStorage:GetChildren()) do ClonedTools = Tools:Clone() ClonedTools.Parent = Player.Backpack end end end) end)
Did I help? Please vote me up, it helps a lot. Thanks.