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

why does it only read the last item ?

its only reading test and not LavaSword

local names = {"LavaSword","test"}
for i = 1,#names do
function clean()
		if Player.Backpack:FindFirstChild(names[i],true) then
			Player.Backpack:FindFirstChild(names[i],true):remove()
		end
end
end

1 answer

✓ Accepted answer

I'm not actually sure what you're trying to do here with that clean function.

I assume you meant to do this:

local names = {"LavaSword","test"}
function clean()
	Player.Character.Humanoid:UnequipTools() --forcefully unequips all Tools, so you don't miss any in the loop.
	for i = 1,#names do
	        if Player.Backpack:FindFirstChild(names[i],true) then
	            Player.Backpack:FindFirstChild(names[i],true):remove()
	        end
	end
end

clean()

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