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

Possible to make this give out 4 tools to a player than one?

Asked by 5 years ago

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)

2 answers

Log in to vote
0
Answered by
gullet 471 Moderation Voter
5 years ago

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)

Ad
Log in to vote
0
Answered by 5 years ago

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
0
You don't have to define a variable for CharacterAdded's passed parameter if you're not going to use it. DeceptiveCaster 3761 — 5y

Answer this question