Clone tool on clicked

How to clone a tool on ServerStorage to player backpack

I’m assuming you’re trying to clone a tool from ServerStorage to the player’s backpack when the player clicks on a button in a GUI, not too sure though.

Here’s some code that will help you out:

-- Server

function AddTool(Player, Tool)
    	if Tool:IsA("Tool") then -- Checking if the Tool is actually a Tool
    		local ClonedTool = Tool:Clone() -- Cloning Tool
    		ClonedTool.Parent = Player.Backpack -- Setting the parent to the backpack
    	end
    end

game:GetService("ReplicatedStorage").ToolEvent.OnServerEvent:Connect(function(Player)
	if not Player.Backpack:FindFirstChild(ToolName) and not Player.Character:FindFirstChild(ToolName) then -- Checking if the tool isnt in the Player's character or backpack
		AddTool(Player, game:GetService("ServerStorage"):FindFirstChild(ToolName)) -- Calling the functions and giving proper arguments 
	end
end)

-- Client 
script.Parent.Button.MouseButton1Click:Connect(function() -- Checking when a button's MouseButton1Click event is fired
	game:GetService("ReplicatedStorage").ToolEvent:FireServer() -- Firing the remote, ToolEvent 
end)

Essentially, what we are doing is that we are creating a function called, AddTool that needs two arguments, the player, and the tool we want to be cloned. In this function, we will first check if the tool is actually a tool, and then clone it and parent it to the Player’s backpack. Then, when the remote called “ToolEvent” is fired, we will call the function with the proper arguments. This “ToolEvent” remote will be fired when whatever button you want is clicked. This is all shown in the code above.

1 Like