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

Delete all players itens which are Parts?

Hello fellow users, I have a game which the tools are instead parts welded to player hands because I do only one time per time (just like Piggy or Teddy) and when the round ends the person still have the item if they survived.

Heres the code I tried:

function deletePlayersItens()
	for i,v in pairs(game.Players:GetChildren()) do
		if v.Name == "Key" then
			print("KABOOOM")
			v:Destroy()
		end 
	end
end

No errors in output, simply nothing. Please help, LyricalFrog3.

2 answers

You're listing through PLAYER List, not their backpacks. You simply just need to loop through players and after it their backpacks With something like this:

function deletePlayersItens()
	for _,v in pairs(game.Players:GetChildren()) do
		for _, Tool in pairs(v.Backpack:GetChildren()) do
			if v.Name == "Key" then
				print("KABOOOM")
				v:Destroy()
			end
		end
	end
end

1 comment

0

Yes I want player list but in their character because my tool isn't a normal roblox tool its a part that when clicked it welds to the player hand and goes to the character so your script doesn't work

not a advanced scripter im really bad at scripting but I maybe saw a typo. Didn't test but might work.

function deletePlayersItems() --- you wrote itens instead of items
    for _,v in pairs(game.Players:GetChildren()) do
        for _, Tool in pairs(v.Backpack:GetChildren()) do
            if v.Name == "Key" then
                print("KABOOOM")
                v:Destroy()
            end
        end
    end
end

2 comments

0

also maybe i, v in pairs instead idk

0

please read the comment I did for the other guy that answered, its not from the backpack, but from the carachter

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