local function z(z)local T=randomGenerator:NextInteger(-z.Size.X/2,z.Size.X/2)local f=randomGenerator:NextInteger(-z.Size.Y/2,z.Size.Y/2)local X=randomGenerator:NextInteger(-z.Size.Z/2,z.Size.Z/2)local Y=Vector3.new(T,f,X)local s=z.CFrame:pointToWorldSpace(Y)local x=math.pi*2 local E=randomGenerator:NextNumber()*x local S=randomGenerator:NextNumber()*x local I=randomGenerator:NextNumber()*x local D=CFrame.Angles(E,S,I)D=D+s return D end

local function getRandomCFrameInVolume(partVolume)

    -- Calculate the position component of the random CFrame
    local x = randomGenerator:NextInteger(-partVolume.Size.X/2, partVolume.Size.X/2)
    local y = randomGenerator:NextInteger(-partVolume.Size.Y/2, partVolume.Size.Y/2)
    local z = randomGenerator:NextInteger(-partVolume.Size.Z/2, partVolume.Size.Z/2)
    local localOffset = Vector3.new(x, y, z)
    local worldOffset = partVolume.CFrame:pointToWorldSpace(localOffset)		

    -- Calculate the rotation component of the random CFrame
    local twoPi = math.pi * 2
    local xRotation = randomGenerator:NextNumber() * twoPi
    local yRotation = randomGenerator:NextNumber() * twoPi
    local zRotation = randomGenerator:NextNumber() * twoPi
    local CFrame = CFrame.Angles(xRotation, yRotation, zRotation)	

    -- Add the position and rotation together to get the full random CFrame
    CFrame = CFrame + worldOffset

    return CFrame
end
