I'm trying to figure out if it's possible to make this script give more than 1 tools to a player (4 tools to be exact)
script:
```lua game.Players.PlayerAdded:connect(function(p)
p.CharacterAdded:connect(function(c)
repeat wait() until p:FindFirstChild("Backpack")
game.Lighting:GetChildren()[math.random(1, #game.Lighting:GetChildren())]:clone().Parent = p.Backpack
end)
wait(2)
end)
Yes, you simply iterate and set the Parent of each tool separately. You're currently only parenting one randomly chosen object. (you should also use ReplicatedStorage
instead of Lighting
now that it is available)
Example:
local tools = game.Lighting:GetChildren()
game.Player.PlayerAdded:Connect(function(p)
p.CharacterAdded:Connect(function(c)
for _, tool in pairs(tools) do
local cloned_tool = tool:Clone()
cloned_tool.Parent = p.Backpack
end
end)
end)
You can fix that by using this script
game.Players.PlayerAdded:Connect(function(player) -- When player enter the game, it will execute this script: player.CharacterAdded:Connect(function(character) -- When your character added into game, the function will execute this script: for _,v in pairs(game.Lighting:GetChildren()) do -- Get all the tool if v:IsA("Tool") then -- Checks if the object is a tool local clone = v:Clone() -- Clone the tool clone.Parent = player.Backpack -- Putting the tool in the backpack. end -- The end of line 4 end -- The end of line 3 end) -- The end of line 2 end) -- The end of line 1