How to make a tool only give once and stays in your inventory

I wanted to make the “e to equip”" give only one tool, but whenever I click the proximitypromt it gives me infinite amount of the tool as shown in the video.
i have the flashlight in serverstorage

and one small thing, how do I make it stays in your inventory when you die.
and also don’t mind the video fps, idk why is it like that

video:

I tried changing some parts of the script but it didn’t worked at all.

the script:

local ToolName = {"Flashlight"}  
local Storage = game.ServerStorage 


local Part = script.Parent.Parent
local ProximityPrompt = script.Parent

ProximityPrompt.Triggered:connect(function(Player)
	if Player and Player.Character then
		local Backpack = Player:WaitForChild("Backpack")
		for i = 1, #ToolName do
			local Tool = Storage:FindFirstChild(ToolName[i])
			if Tool then
				Tool:clone().Parent = Backpack
			end
		end
	end
end)

I’d place a clone of the tool in the player’s backpack and another clone into their startergear when it is given to the player

1 Like

In addition to what 4SHN said, before you give the tool, make sure it’s

  1. Not already equipped.
  2. Not already in their backpack.

That way you only give it once. A question comes to mind though… Does the player get to keep the tool even when they log off?

Check if the Player has the tool in their inventory So like this

local PlayerHasTool = Player.Character:FindFirstChild("YourToolName") or Player.Backpack:FindFirstChild("YourToolName")

if PlayerHasTool then
       -- the Player has the tool so return
     return
else
-- Clone the tool into player's backpack
end

Now to make the tool stays in your inventory You would make its Parent to StarterGear
If you are talking about even if the player leaves then you have to make a datastore for it
You could use tables Here I’ll give you the Player leaving code:

game.Players.PlayerRemoving:Connect(function(Player)
local ToolsTable = {}
for i,Tool in pairs(Player.Backpack:GetChildren())
table.insert(ToolsTable, Tool)
end)
1 Like

If I understand correctly, you’re trying to make it so that you can only put the tool in your inventory once, and that it stays in your inventory even after it dies. Then try this:

local ToolName = {"Flashlight"}  
local Storage = game.ServerStorage 


local Part = script.Parent.Parent
local ProximityPrompt = script.Parent

ProximityPrompt.Triggered:connect(function(Player)
	if Player and Player.Character then
		local Backpack = Player:WaitForChild("Backpack")
		local StarterGear= Player:WaitForChild("StarterGear")
		for i = 1, #ToolName do
			local Tool = Storage:FindFirstChild(ToolName[i])
			if Tool and backpack:FindFirstChild(Tool.Name) == nil and Backpack:FindFirstChild(Tool.Name) == nil then
				Tool:clone().Parent = Backpack
				Tool:clone().Parent = StarterGear
			end
		end
	end
end)

The StarterGear causes the tools that are there to clone the backpack when it respawns.

2 Likes