✓ 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
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 (:
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.
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!