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

How can I make it where a player is limited to 1 of each tool?

How can I make it where a player is limited to 1 of each tool?

4 comments

0

Or if possible, how can I make it where when someone collects an item, they can never see that item pop-up again?

0

You need to elaborate a bit, how does the player get the tool in the first place? If they get the tool through a script it would be super easy to check if they already have it.

0

Yes, once they collect it they can't see it anymore.

0

It doesn't have to be a tool, I'm trying to make an artifact/treasure hunting game and I wanted it so that every time you find an artifact it goes into a journal and you can go and sell it.

2 answers

Just check it with :FindFirstChild() everytime the server gives the player a new tool/item Example:

local toolName -- your tool name from remote event/function or something else
local hasTool = player:WaitForChild("Backpack"):FindFirstChild(toolName)

if hasTool then
   warn("player has " ..toolName.. " already!")
else
   -- do whatever you want
end

You can make it so it checks if the player already has that tool for example:

local tool = game.ReplicatedStorage.Tools:WaitForChild("BloxyCola") -- This is just an example

function giveTool(Tool, plr)
	if not plr.Backpack:FindFirstChild(tool) then
		Tool:Clone().Parent = plr.Backpack
		-- Do whatever you want
	else
		warn(plr.Name.." already has "..Tool.Name.."!")
		-- Do whatever you want
	end
end

-- The function must be connected to some kind of event for example
game.Workspace.GiverPart.ClickDetector.MouseClick:Connect(function(playerThatClicked)
	giveTool(tool, playerThatClicked)
end

You can also do it like this

local tool = game.ReplicatedStorage.Tools:WaitForChild("BloxyCola") -- This is just an example

game.Workspace.GiverPart.ClickDetector.MouseClick:Connect(function(plr)
	if not plr.Backpack:FindFirstChild(tool) then
		tool:Clone().Parent = plr.Backpack
		-- Do whatever you want
	else
		warn(plr.Name.." already has "..tool.Name.."!")
		-- Do whatever you want
	end
end

All of this was an example so you should use your imagination and modify the script to your needs but hopefully I helped and you understood what I tried to tell you.

But if this was too complex to you then you can either research more about the things on this script, search for a simpler method or check other answers by other users or if you have any other problem just ask me.

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