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

When in the area more than one object, delete one?

Asked by 3 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.

Hi, I need help with a script. When in the area is more than one object, need to delete one, but I either delete everything or no one.

I also wanted to make both the area and the part anchored, but in this case script does not work.

Area - anchored part, Part - select all parts in folder.

Please, help!

local Part = workspace:WaitForChild("Part"):GetChildren()
local Area = game.Workspace.Area

Area.Touched:Connect(function(hit)
    if hit.Name == "Part" then
        Part:Destroy()
    end
end) 

1 answer

Log in to vote
1
Answered by 3 years ago

Hello, if I understand well, you want to delete all parts in a certain area, except for one? Please tell me if I misunderstood.

local part = script.Parent -- area is the parent of this script


for i, v in pairs(part:GetTouchingParts()) do -- i is the variable keeping track of the index, v in the part itself, part:GetTouchingParts() returns a table of all parts touching the area
    if i ~= 1 then -- if index is not 1, delete the part, which means that the part with index 1 will not be deleted
        v:Destroy()
    end
end

This script should work if that's what you want.

Please elaborate on the anchored part.

0
You got it right, thank you. LioshaPlay 66 — 3y
Ad

Answer this question