How to make a pickup tool

How can i make a pickup tool so that when i pick it and get in my inventory it already has all of the scripts and stuff to work like i originally wanted the tool to work like.
image

1 Like

I did do that but now is there a way i can access the tool from backpack? I need it for a few touched events

local Server = game:GetService("ServerStorage")
local Tool = Server.Tool --Change to name of tool.

local Part = script.Parent
local Click = Part.ClickDetector

Click.MouseClick:Connect(function(Player)
	local Character = Player.Character
	local Backpack = Player.Backpack
	
	local CharacterTool = Character:FindFirstChild(Tool.Name)
	local BackpackTool = Backpack:FindFirstChild(Tool.Name)
	
	if CharacterTool or BackpackTool then --Avoids giving the player duplicate tools.
		return
	end
	
	local ToolClone = Tool:Clone()
	ToolClone.Parent = Backpack
end)

Here’s a relatively primitive example which makes use of a ClickDetector instance, additionally a check is performed to verify that the user hasn’t already received the tool before awarding the tool to them.

Here’s the model file for reproduction purposes.
repro.rbxm (9.4 KB)

The “BasePart” instance can be placed anywhere in the workspace and the “Tool” instance should be placed inside the ServerStorage folder.

Well i tried changing it to the name of tool but it didnt work.

local Tool = Server["Throwing Knife"] --Change to name of tool.

local Part = script.Parent
local Click = Part.ClickDetector

Click.MouseClick:Connect(function(Player)
	local Character = Player.Character
	local Backpack = Player.Backpack

	local CharacterTool = Character:FindFirstChild(Tool.Name)
	local BackpackTool = Backpack:FindFirstChild(Tool.Name)

	if CharacterTool or BackpackTool then --Avoids giving the player duplicate tools.
		return
	end

	local ToolClone = Tool:Clone()
	ToolClone.Parent = Backpack
end)

This is a server script right? Only server scripts can access ServerStorage.

So do i dump the script into server script?

It’s intended to be a server script, yes.

Just wanted to say, Forummer already said the answer but a tool works to its fully function if the tool is in workspace when the player touches it. It automatically moves it to their character and all the scripts work too

Yeah it does, it moved under the player, mb.

i want it so that you click on it not touch it

Yeah, as you stated, receive on touch is the standard behavior for tools (but isn’t always desired).