Clone a tool to all players backpack ingame

Hello does anyone know how I clone a tool for all player’s in-game

This my script

local Event = game:GetService("ReplicatedStorage").Events.FlashEquip

Equipped = false

Event.OnServerEvent:Connect(function(Player)
	if Equipped == false then
		Player.Backpack:WaitForChild("Flashlight").Parent = Player.Character
		Equipped = true
	else
		Player.Character:WaitForChild("Flashlight").Parent = Player.Backpack
		Equipped = false
	end
	Player.Character.Humanoid.Died:Connect(function()
		Equipped = false
	end)
end)

so the problem is in this script the player who activated the event only will get the tool

but I want if the player activates the event all players in the game will get the tool

You can try to do this (that’s not the best way, there’s better ways but I don’t know how to do them)

for i, v in pairs(game.Players:GetChildren()) do
   tool:Clone().Parent = v.Backpack
end

instead of using game:GetService("Players"):GetChildren() you should use :GetPlayers() instead.

1 Like

Here is an example that should help you:

Event.OnServerEvent:Connect(function(PlayerWhoActivated)
    -- The object to clone from.  You might want to get this from ReplicatedStorage instead.
 -- local tool = game:GetService("ReplicatedStorage"):WaitForChild("Flashlight")
    local tool = PlayerWhoActivated.Backpack:WaitForChild("Flashlight")

    -- Iterate through each player in the game
    for index, player in pairs(game.Players:GetPlayers()) do
        -- Clone the tool to each player's backpack if they don't already have it.
        if not player.Backpack:FindFirstChild(tool.Name) then
            tool:Clone().Parent = player.Backpack
        end
        
        -- Make each player equip the tool.
        local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
        if humanoid then
            local tool_to_equip = player.Backpack:FindFirstChild(tool.Name)
            if tool_to_equip then
                humanoid:EquipTool(tool_to_equip)
            end
        end

    end

end)

Can you add this to my script because whenever I add it says error messing end and idk

Most likely your code is formatted incorrectly, this is a syntax error.

You really should figure out how to implement this in your script, rather than asking people to write your code for you.