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

How do i can make a For to delete all workspace items with same name?

Im making a script that spawn a Throne in front of me, but sometimes when i die, it bug and i can spawn 2 thrones a time, i made a script that "when i press B, it spawn, when i press B again, it :Destroy", but when existe 2 of it, my script only destroy 1, i made a for to search all Workspace items with the Throne name, but its not working, wt im making wrong?

For Script:

if throneExists then
		for _, v in pairs(game.Workspace:FindFirstChild("BaragganThroneRemote")) do
			v:Destroy()
			wait(.1)
		end
	else
		local clone = model:Clone()
		
		clone.Parent = workspace
		clone:PivotTo(character.HumanoidRootPart.CFrame * CFrame.new(0, 1.3, 0) * CFrame.Angles(math.rad(180), math.rad(90), math.rad(0)))
	end

4 comments

0

Idk how you set up the workspace, but assuming you have a folder with all the parts of the throne, then you simply just reference the folder and folder:GetChildren():Destroy(). This is not an exact solution but you try something similar to this

0

or you can select all the parts of the throne and hit Ctrl + G to make it a model and make your script summon and destroy the model

0

its already a model, its that "BaragganThroneRemote", i want a For that keep searching if there's something named "BaragganThroneRemote" in the Workspace and If Yes, destroy it.

0

@Shampoo02496 - GetChildren() returns an array, not an instance object. Calling Destroy() on GetChildren() will throw an invalid property error.

1 answer

Add a ":GetChildren()" to get all the Childs of a Parent

for i,v in pairs (game.Workspace:FindFirstChild("BaragganThroneRemote"):GetChildren()) do
v:Destroy()
wait(0.1)
end

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