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

Script will delete everything except what a player is holding, how to fix?

I'm making a game that needs to delete EVERYTHING in the player's backpack once the map has deleted, but it deletes everything except what the player is holding.. How do I fix this??

Here is the script:

for key = 1, #players do -- Increment the key variable every iteration until it reaches the amount of players
    local value = players[key]; -- Create a reference to the player
    value.Backpack:ClearAllChildren(); -- Clear their backpack
end

1 comment

0

btw before anyone asks, yes I used this script from someone else, but I can't figure out how to fix it

2 answers

✓ Accepted answer
for _,v in pairs(plr.Character:GetChildren()) do
	if v:IsA("Tool") then
		v:Destroy()
	end
end

An easier alternative to what @Happywalker did would to use the :UnequipTools()


for key = 1, #players do
    local value = players[key]
    if value.Character and value.Character:FindFirstChild('Humanoid') then
           value.Character.Humanoid:UnequipTools()
    end
    value.Backpack:ClearAllChildren()
end

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