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)
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.