I’m basically just trying to iterate through the table FindPartsInRegion3() creates. I’m creating the region on server start, and that part seems to be working perfectly fine.
However, for some reason when I try to iterate through the table, it just… wont work? The script literally just stops there and I have no idea why.
local event = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("near")
local within = false
local pos1, pos2, region
local plr
for _,v in pairs(workspace.WorkoutEquipment:GetChildren()) do
if v:FindFirstChild("headpoint") ~= nil then
print("yuh")
local headpoint = v:FindFirstChild("headpoint")
pos1 = v.pos1.Position
print(pos1)
pos2 = v.pos2.Position --headpoint.Position + Vector3.new(2, 5, -10)
print(pos2)
region = Region3.new(pos1, pos2)
print(tostring(region.Size).." This is the size of the region3")
--see region
local part = Instance.new("Part", workspace)
part.Name = "REGION"
part.CanCollide = false
part.Anchored = true
part.Transparency = .5
part.CFrame = region.CFrame
part.Size = Vector3.new(math.abs(region.Size.X), math.abs(region.Size.Y), math.abs(region.Size.Z))
end
end
while true do
wait(1)
print("lets get started")
print(region.CFrame)
for i,v in pairs(workspace:FindPartsInRegion3(region)) do -- stops here
print("cool")
if v.Parent:FindFirstChild("Humanoid") ~= nil then
print("ok2")
plr = game.Players:GetPlayerFromCharacter(v.Parent)
print(plr.Name)
print("ok3")
end
end
end
Everything after the pairs loop with the comment next to it doesn’t run. Any help is appreciated!
It looks to me like you are creating multiple regions and setting them all to the same variable which means only the last region will work, I could be wrong though.
that might be the case for future entries to that “WorkoutEquipment” folder, but for the time being it only has one model in it. so, I don’t think thats cause.
Are you sure things are inside the region specified? If nothing inside the for loop prints it could be due to the fact that there is actually nothing in the region.
https://gyazo.com/945bc0dc9a9e8b575e76278f1f27474b not only does my player move through the region, but the region is created ontop of other parts(not above 20.) i’m pretty sure there is stuff within the region, either way let me check real quick.
well… it seems that there really isn’t anything within my region3…
if #workspace:FindPartsInRegion3(region) == 0 then
print("there is none")
elseif #workspace:FindPartsInRegion3(region) < 0 then
print("THERE IS STUFF IN HERE!")
end
I’ve checked to make sure that my region isn’t too small by printing its Size and checked its CFrame as well. I’ve also made sure to lower the wait time but to no avail, it deemed the same results https://gyazo.com/c38a707313224499f40d2b1bd6ad7bf2 any other solutions maybe?