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

limit same tool in backpack?

3 answers

imma assume that when a player touch a brick, the game gives them a sword


local Sword = game.ServerStorage.Sword --- or where ever the sword tool is stored
local SwordString = tostring(Sword)
script.Parent.Touched:Connect(function(player) -----This script must be in the part which is desired to give the sword

	local backpack = game.Players[player.Name]:WaitForChild("Backpack")

	if backpack:FindFirstChild(SwordString) then --- checking for sword in the player
		print("player already has item") --- code that fire if there is already a sword
	else
		local SwordCopy = Sword:Clone() --- if there isn't a sword, copy the original
		SwordCopy.Parent = backpack --- set the parent of the sword to the player's backpack
	end

)

If you need anymore questions, reply to this

It's pretty simple. When you give them the sword, you make a check inside their backpack to see if that item already exists. You could do something like this:

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		-- Now we will first check if they already own the item.
		if not player.Backpack:FindFirstChild("ItemNameHere") then
			ItemName:Clone().Parent = player.Backpack
		end
	end
end)

Hope it helped.

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