Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
262187 45
8 years ago

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

0
All you have to do is check if the part is a descendant of the player's character. dirty_catheter 7 — 8y
0
Would I have to make another If statement or could I make it in the table "Ignore" ? 262187 45 — 8y

1 answer

Log in to vote
1
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

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
0
I re-arranged things to my wants but overall it worked thanks! 262187 45 — 8y
Ad

Answer this question