[SOLVED] Help cloning a item into the players' backpack

Hey there,

I need help cloning a tool into the players’ backpack.
This is my script:

local ServerStorage = game:GetService("ServerStorage")
local player = game.Players.LocalPlayer

local function Grab()
	-- what to go here?
end

script.Parent.ProximityPrompt.Triggered:Connect(Grab)

Any help is appreciated!

1 Like

Is that a LocalScript or server script?

Make sure it’s a server script if it isn’t, and change your code to this:

--//Services
local ServerStorage = game:GetService("ServerStorage")

--//Variables
local Tool = ServerStorage.MyCoolTool --//Reference your tool
local Part = script.Parent
local ProximityPrompt = Part.ProximityPrompt

--//Functions
ProximityPrompt.Triggered:Connect(function(player)
	local newTool = Tool:Clone()
	newTool.Parent = player.Backpack
end)

If you want it to only be grabbed once, here’s the code for that:

--//Services
local ServerStorage = game:GetService("ServerStorage")

--//Variables
local Tool = ServerStorage.MyCoolTool --//Reference your tool
local Part = script.Parent
local ProximityPrompt = Part.ProximityPrompt

--//Functions
ProximityPrompt.Triggered:Connect(function(player)
	if player:FindFirstChild(Tool.Name) then
		return
	end
	
	local newTool = Tool:Clone()
	newTool.Parent = player.Backpack
end)
1 Like

Will check it out, Thanks for the reply!

You would want to put the item into the thing called “backpack” in the player instance. You should be doing this server side as well.

That code does work, but I can still equip it multiple times.

To check if a player has a tool

if Player.Backpack:FindFirstChild(Tool.Name) or Player.Character:FindFirstChild(Tool.Name) then
   return
end

You also need to check the character, because when they hold a tool it is not in their Backpack, but it is in their character

Let me record a video, give me a second.

If the devforum says the video size is too big, you can decrease it with this.

local ServerStorage = game:GetService("ServerStorage")

script.Parent.ProximityPrompt.Triggered:Connect(function(Player)
	if Player.Backpack:FindFirstChild("ToolName") or Player.Character:FindFirstChild("ToolName") then
		print("Player has tool already")
	else
		local Tool = ServerStorage:WaitForChild("ToolName"):Clone()
		Tool.Parent = Player.Backpack
	end
end)

Try do something like this, it worked fine for me.

1 Like

Here is a video

this shoud be work without dups

local Tool = ST.Tool --tool
local PP = script.Parent --proximityprompt

PP.Triggered:Connect(
    function(player)
        if player.Backpack:FindFirstChild(Tool.Name) then
            return
        end
        local newTool = Tool:Clone()
        newTool.Parent = player.Backpack
    end
)

Trying it out!

No, if you hold the tool it will go into their character, and you’re only checking the backpack, but not the character

1 Like

:heavy_check_mark: TOPIC SOLVED :heavy_check_mark:

1 Like