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:
1 | function 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. |
5 | end |
6 |
7 | script.Parent.ClickDetector.MouseClick:connect(GearGive) |
Use FindFirstChild() function to check if player has the tool already.
1 | function GearGive(x) |
2 | local y = x.Backpack |
3 | local z = game.Lighting [ "ClassicSword" ] --Change "GEARNAME" to the name of the item. |
4 | if not y:FindFirstChild( "ClassicSword" ) then --check if player has classicsword in their backpack |
5 | z:Clone().Parent = y -- put item in lightning. |
6 | end |
7 | end |
8 | script.Parent.ClickDetector.MouseClick:connect(GearGive) |