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

Remove one Tool from players backpack of the same kind?

Just a quick one that I can't get my head around, what would be the quickest route about removing one Tool of a kind from a players backpack?

For example, say the players have 5 of the same sword... How could I only remove one of them? I've tried loops and stuff but it seems to remove them all.

Thanks, Cuv

1 answer

✓ Accepted answer

If you can find a way to make sure each weapon has a unique name this will work. If it doesn't equal a certain Name it will remove it. So you have you MainWeapon for example, and you have a verification script on the side that will change the name if one already exists. Now you have MainWeapon and Weapon2. Whenever the script checks it will remove Weapon2 since it isn't the right one. You can also add an OR statement so you can have multiple weapons. Of course, none of this is required if you check for a pre-existing weapon before giving it to the Player. This is a LocalScript inside of "StarterPlayerScripts"

while true do
	local person = script.Parent.Parent
wait(5)
	

for i, v in pairs(person.Backpack:GetChildren()) do
	
if v.Name ~= 'MainWeapon' then
v:Destroy()


end
end
end

3 comments

0

Ah I've already tried this method, would it be possible to remove just one though? For example, say there were 5 weapons named MainWeapon and I want to only remove one so the player has 4? This is for an inventory system I made that's why the player could possibly have more than one xD anyways if you know ill accept this answer (:

0

That was my original thought actually. I'm not 100% how to do it. If you can count the number of objects with the same name and store that number in a NumberValue, then I know how. Your script could then do some math wizardry and say 5-4 = 1 so it will remove 4.

0

That's a lot of work! The only problem is that this question violates the SH terms and could've been deleted so you did all that work for no reason! Try avoiding these bad questions because you might accidently answer a question that gets deleted!

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