You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
detect how many parts are in an area
What is the issue? Include screenshots / videos if possible!
I have a hard time figuring it out
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
while task.wait(.1) do
for i, v in pairs(game.Workspace:GetPartsInPart(script.Parent)) do
if v:FindFirstChild(“Detect”) then
print(v)
local count = 0
for _,s in pairs(game.Workspace:GetPartsInPart(script.Parent)) do
count = count + 1
end
print(count)
end
end
end
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
while task.wait(.1) do
for i, v in pairs(game.Workspace:GetPartsInPart(script.Parent)) do
if v:FindFirstChild("Detect") then
print(v)
local count = 0
for _,s in pairs(game.Workspace:GetPartsInPart(script.Parent)) do
count = count + 1
end
print(count)
end
end
end
I WANT TO DETECT HOW MANY PARTS ARE IN AN AREA FOR EXAMPLE:
print(partsinareanumber)
and it prints the number of parts in that area and it only detects it when it has the detect value
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
If your just looking to basically see how many parts are inside of a part u could just do this…
function GetPartsInPart(Part : BasePart)
return Part:GetTouchingParts()
end
print(GetPartsInPart(script.Parent))
or if the part needs to have the child ‘Detect’ do this…
function GetPartsInPart(Part : BasePart)
local TouchingParts = Part:GetTouchingParts()
local PartCount = 0
for _,TouchingPart in ipairs(TouchingParts) do
if TouchingPart:FindFirstChild('Detect') then
PartCount += 1
end
end
return PartCount
end
print(GetPartsInPart(script.Parent))
So what you’ll have to do for that is make a table of all the parts detected in the area and has the value of the position in it, once you have that then when you run through each part you can go through the list to find the part and if the table logged position is different from the current part position then you’ll know if it moved
for some reason it is only detecting 2 or 3 objects whenever i manually move the objects ingame in that region… it may be because of it is detecting the same object twice?
You can just use my script listed above and if you want it to constantley be checking for parts in the designated region/part then just put it in a loop such as
GetPartsInPart(script.Parent) -- script.Parent is the part you want to detect the parts in