For loop not working

I have a script inside severscriptservice thats “supposed” to destroy everything inside a folder in the workspace. However it just doesn’t work? It is printing when the remote event is recieved btw.

game.ReplicatedStorage.SendClear.OnServerEvent:Connect(function(plr)
	print("Ruz")
	for i, items in pairs(game.Workspace.Dropped:GetChildren()) do
		items:Destroy()
	end
end)
1 Like

yeah that’s strange, maybe check the instances in the folder by using IsA()? like if you just have a bunch of parts, you could check using that

1 Like
game.ReplicatedStorage.SendClear.OnServerEvent:Connect(function(plr)
	print("Ruz")
	for i, items in pairs(game.Workspace.Dropped:GetChildren()) do
		if items:IsA("Tool") then
			items:Destroy()
		end
		
	end
end)

its still not working…

1 Like

No errors? Add a print statement in the for loop to see if it’s working properly

1 Like

Yep No errors but nothing is printing within the for loop tho…

1 Like

It doesn’t need to iterate over anything in a order right? If you’re just deleting everything you can do

game.ReplicatedStorage.SendClear.OnServerEvent:Connect(function(plr)
	print("Ruz")
	for i, items in workspace.Dropped:GetChildren() do
		if items:IsA("Tool") then
			items:Destroy()
		end
		
	end
end)

Are the tools just on the floor in a folder?

1 Like

They are in a folder on the floor, and yes they can be destroyed in any order

1 Like

Can you send a SS of the workspace?

1 Like

Now you mention it I just realized that the tools are being made on the client so it can’t be destroyed on the server. silly me lemme try again

1 Like

Ah yep, that’ll do it. :sob: , weird that it gave no error.

2 Likes

There you go its working now. Thanks for helping me use my brain!

1 Like

Note: you can simply do

for i,v in table do
    -- code
end

EDIT: Grammar

1 Like

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