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

How to prevent a duplicated tool in a player's inventory?

So, im making a game where you find objects (gears/tools). I made a ClickGiver (a part) for the tool, but i want the player to have no more than 1 copy of the same tool. Is there a way to put a function for do it in the same script or i need to insert a LocalScript?

Here is how the giver works:

function GearGive(x)
	local y = x.Backpack
	local z = game.Lighting["ClassicSword"] --Change "GEARNAME" to the name of the item.
	z:Clone().Parent = y   -- put item in lightning.
end

script.Parent.ClickDetector.MouseClick:connect(GearGive)

1 answer

✓ Accepted answer

Use FindFirstChild() function to check if player has the tool already.

function GearGive(x) 
local y = x.Backpack
local z = game.Lighting["ClassicSword"] --Change "GEARNAME" to the name of the item. 
if not y:FindFirstChild("ClassicSword") then --check if player has classicsword in their backpack
z:Clone().Parent = y -- put item in lightning. 
end 
end
script.Parent.ClickDetector.MouseClick:connect(GearGive)

2 comments

0

THANKS! IT WORKS!

0

No problem.

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