Problem with deleting parts

I want to delete parts by debris but only one deletes and others stays. I used Debris.

local clonedBackgrounds = {}
local clonedfloors = {}
local cloneddiscs = {}

game:GetService("ReplicatedStorage").MusaS1.OnServerEvent:Connect(function(player)
	if player.Character then
		local tool = player.Character:FindFirstChild("Magic Finix Musa")

		if tool then
			local character = player.Character
			local humanoid = character.Humanoid

			local clonedBackground = background:Clone()
			clonedBackground.Name = "localBackground
			
			local cfloor = floor:Clone()
			cfloor.Parent = workspace
			cfloor.Name = "LocalFloor"
			
			local discC = disc:Clone()
			disc.Name = "LocalDisc"
			discC.Parent = workspace
			
			cloneddiscs[player] = discC
			clonedfloors[player] = cfloor
			clonedBackgrounds[player] = clonedBackground
			
			humanoid.Died:Once(function()
				debris:AddItem(clonedBackgrounds[player], 0)
				clonedBackgrounds[player] = nil
				debris:AddItem(cloneddiscs, 0)
				cloneddiscs[player] = nil
				debris:AddItem(clonedfloors, 0)
				clonedfloors[player] = nil
			end)
			
	---rest script
			task.wait(5)
			
			debris:AddItem(clonedBackground, 0)
			debris:AddItem(discC, 0)
			debris:AddItem(cfloor, 0)

			humanoid.WalkSpeed = 16
			humanoid.JumpHeight = 7.2
			character.PrimaryPart.Anchored = false


			tool:Destroy()
		else
			warn("Magic Finix Amber isn't equipped!")
		end
	else
		warn("player.Character is currently nil")
	end
end)

game.ReplicatedStorage.ChangePlayerCharacter.OnServerEvent:Connect(function(player)
	debris:AddItem(clonedBackgrounds[player], 0)
	clonedBackgrounds[player] = nil
end)
2 Likes

You are only referencing the clone for clonedBackground, for the other ones you are referencing the table with all the clones in it.

Here is it fixed:

humanoid.Died:Once(function()
	debris:AddItem(clonedBackground, 0)
	clonedBackgrounds[player] = nil
	debris:AddItem(discC, 0)
	cloneddiscs[player] = nil
	debris:AddItem(cfloor, 0)
	clonedfloors[player] = nil
end)

I will try if that will work. Because Iā€™m not good at debris, it is so confusing

Okay it has nothing to do with Debris. It has to do with the fact that 2 out of the 3 things you added to the debris were not the things you intended to add.

Debris works very simply. You call debris:AddItem() and pass two arguments. The first argument being the Instance you want destroyed and the second argument a number for how many seconds you want to wait before destroying the item.

I used there a table with pharametr [player] after it

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.