Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make it so you can only pick up one instance of a tool?

For example, if I had a bunch of tools lying on the floor called 'Pistol', how would I make it so once a player has one in their inventory, they can't pick up another?

Thanks,

  • Sam4550.

1 answer

✓ Accepted answer

Well, I'd put the tool as a model in Workspace, not the actual Tool itself. So, you'd have a model that you can't pick up. Then, from there, I'd add a Touched event and put it inside the biggest part if the model. Then, once I have my Touched Event laid out, I'll use the FindFirstChild Method to check if the Player already has it. If not, it'll then clone it and put it in their Backpack.

Tool = "Tool name here"

script.Parent.Touched:connect(function(hit) -- Touched Event w/ the connection line
	if hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) then -- Checks if it's a player
		p = game.Players:GetPlayerFromCharacter(hit.Parent) -- Sets the player variable
		if not p.Backpack:findFirstChild(Tool) then -- Checks if it is in their backpack. If not, then do the following
			copy = game.ServerStorage[Tool]:clone() -- clone the tool
			--copy2 = game.ServerStorage[Tool]:clone()
			copy.Parent = p.Backpack -- put it in their backpack
			--copy2.Parent = p.StarterGear
			script.Parent.Parent:Destroy() -- Destroys the fake gun (Model). Make sure this leads to the ACTUAL Model
		end
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.