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

How do I make this region3 script delete un-anchored parts without killing players?

So I have a region3 and I noticed that i can't run a function which deletes un-anchored parts in a region without killing players inside the region.

How would I make it so it does not kill players in the region, but delete unknown un-anchored blocks.

(

Ignore = {workspace.Secure,game.Players} 

local topCorner = script.Parent.TopCorner.Position 
local bottomCorner = script.Parent.BottomCorner.Position
local region3 = Region3.new(bottomCorner, topCorner) 
while wait(0.5) do 
	local parts = workspace:FindPartsInRegion3WithIgnoreList(region3,Ignore,100)
	for i = 1, #parts do
		if parts[i].ClassName == "Part" and parts[i].Anchored == true or parts[i].ClassName == "WedgePart" or parts[i].ClassName == "TrussPart" then -- If I only do "parts[i].ClassName == "Part"" then it kills players.
			if parts[i].Name == "BottomCorner" or parts[i].Name == "TopCorner" then
				parts[i]:Remove()
			else 
				print("Detected "..parts[i].Name.." In Region, ... Deleting ...")	
			end
		parts[i]:Remove()
		end	
	end
end

2 comments

0

All you have to do is check if the part is a descendant of the player's character.

0

Would I have to make another If statement or could I make it in the table "Ignore" ?

1 answer

✓ Accepted answer

If you want to delete all of the unanchored parts in a region that aren't part of a character, check that they aren't inside of a character:

local region3=Region3.new(script.Parent.BottomCorner.Position,script.Parent.TopCorner.Position)
while wait(.5)do
	local parts=workspace:FindPartsInRegion3WithIgnoreList(region3,{workspace.Secure})
	for i=1,#parts do
		local p=parts[i]
		if p:IsA("BasePart")and not p.Anchored then
			local character=false
			for _,v in pairs(game.Players:GetPlayers())do
				if v.Character and p:IsDescendantOf(v.Character)then
					character=true
					break
				end
			end
			if not character then
				p:Destroy()
			end
		end
	end
end

1 comment

0

I re-arranged things to my wants but overall it worked thanks!

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