Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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:

1function GearGive(x)
2    local y = x.Backpack
3    local z = game.Lighting["ClassicSword"] --Change "GEARNAME" to the name of the item.
4    z:Clone().Parent = y   -- put item in lightning.
5end
6 
7script.Parent.ClickDetector.MouseClick:connect(GearGive)

1 answer

Log in to vote
0
Answered by
zuup123 99
4 years ago

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

1function GearGive(x)
2local y = x.Backpack
3local z = game.Lighting["ClassicSword"] --Change "GEARNAME" to the name of the item.
4if not y:FindFirstChild("ClassicSword") then --check if player has classicsword in their backpack
5z:Clone().Parent = y -- put item in lightning.
6end
7end
8script.Parent.ClickDetector.MouseClick:connect(GearGive)
0
THANKS! IT WORKS! NerfLambdaWarrior120 3 — 4y
0
No problem. zuup123 99 — 4y
Ad

Answer this question