Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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:

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

✓ Accepted answer

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

1 comment

0

You don't have to define a variable for CharacterAdded's passed parameter if you're not going to use it.

This discussion is preserved as it was. New answers, comments, and votes are closed.