Non-consistent values with region3

  1. I’m calculating cubic meters from studs, 1 metre is exactly 3.5714285714285714286 studs (but I round this down to 3.57 so it should in actuality be around 0.998800479936 studs since we have 0.9996 meters on each side of the cube)

  2. When I ask the “assistant” AI to spit out a script for calculating total volume it gives a script example.

-- Assume we have a model with parts, and we want to calculate the internal volume
local model = script.Parent
local cubicVolume = 0

-- Conversion factor from studs to meters
local studToMeter = 0.28

-- Iterate through each part in the model
for _, part in pairs(model:GetDescendants()) do
    -- Check if the object is a part
    if part:IsA("BasePart") then
        -- Calculate the volume of the part in studs
        local partVolumeStuds = part.Size.X * part.Size.Y * part.Size.Z
        -- Convert the volume to cubic meters
        local partVolumeMeters = partVolumeStuds * studToMeter^3
        cubicVolume = cubicVolume + partVolumeMeters
    end
end

-- Print the total internal volume in cubic meters
print(cubicVolume)
  1. The assistant AI tried redefining the conversion factor like this, but this led to another inconsistent result (35 instead of 32)
local partVolumeMeters = partVolumeStuds * studToMeter^3

to

local partVolumeMeters = partVolumeStuds * conversionFactor

where conversionFactor is defined as

local conversionFactor = studToMeter^3

Why are these values so far off of the intended ~0.9988 meters I get from hand calculating?

1 Like

I tried doing

-- Assume we have a model with parts, and we want to calculate the internal volume
local model = script.Parent
local cubicVolume = 0

-- Conversion factor from studs to meters
local studToMeter = 0.28

-- Iterate through each part in the model
for _, part in model:GetDescendants() do
	-- Check if the object is a part
	if part:IsA("BasePart") then
		-- Calculate the volume of the part in studs
		local partVolumeMeters = (part.Size.X * studToMeter) * (part.Size.Y * studToMeter) * (part.Size.Z * studToMeter)
		cubicVolume = cubicVolume + partVolumeMeters
	end
end

-- Print the total internal volume in cubic meters
print(cubicVolume)

but this gives a end result of 33 in my output panel

what is causing this massive inconsistency?

it seems the problem lays with

-- Iterate through each part in the model
for _, part in model:GetDescendants() do
	-- Check if the object is a part
	if part:IsA("BasePart") then

itself

when I just do

local model = workspace.part
local cubicVolume = 0

-- Conversion factor from studs to meters
local studToMeter = 0.28

-- Iterate through each part in the model
	if model:IsA("BasePart") then
		-- Calculate the volume of the part in cubic meters
	local volume = model.Size.X * model.Size.Y * model.Size.Z * studToMeter^3
		-- Add the volume to the total
		cubicVolume = cubicVolume + volume
	end
print(cubicVolume)

it prints out the expected value normally

16:15:02.823  0.9988004239048034  -  Server - Script:26