Make a player limited to 1 of each tool?

Okay so, I’m practicing my scripting, and I made a shop, and I’m trying to make it so the player can only have one of each tool Down below is my script that I made. It is supposed to make each player limited to 1 of each tool. There are no errors, if you need me to link anything else tell me.


1 Like

The trivial solution is to, before adding the new tool, call:

Player.Backpack:ClearAllChildren()

2 Likes

Oh, thanks! I was actually getting stressed because I only have been scripting for a week so I don’t know all of these events yet. You’re a lifesaver!

1 Like

Also, what line do I put this on? Line 39?

Sorry, I’m on mobile right now but I think this should work.

:Connect(function(player)
  player.Backpack:ClearAllChildren()
  local newMic = game.ReplicatedStorage:FindFirstChild(“Mic1”):Clone()
  newMic.Parent = player.Backpack
end)

It’s fine. Let me try this and see if it works.

Nope, doesn’t work. Or I must be putting it in the wrong place.

This is where I put it.

Ah, so by using the :ClearAllChildren(), the if block is unnecessary. I think some of the logic is messed up inside the if block as well.

Copy and paste my solution starting with the :Connect(… and I think it will achieve what you are looking for.

Sure. And no, I don’t have any errors.

Here is a screenshot of the script.

1 Like

Nvm, I wasn’t paying attention earlier. Is it clearing your inventory at all?

Nope, it isn’t clearing at all.

I must be putting the script in the wrong place.

Where is it located? Server scripts should be in SeverScriptService

My script is located in ServerScriptService

Case scenario #1:
Player does not have it equipped.

Just check using FindFirstChild in the player’s backpack.

Case scenario #2:
Player does have it equipped.

Also check player’s character.


You could do this on server, if you knew how the properties worked. Make sure you have some kind of event trigger to see if the player’s backpack’s children change or if the character’s children change.

Perhaps this event?

Alright, let make set up an event real quick.

And I also just realised I’m doing it in my rebirths event. Clumsy me.

@anon81993163 is right in that you also want to check the player’s character for equipped tools. However, since you didn’t equip any of the tools when testing, the remote event should clear the player’s backpack.

I would do a sanity check and print something random at the start of the function as well as the player.Name to verify it is being called correctly.