How to keep parts in an area

I have a script that makes a small ice cover for parts close enough to it and I’m using a box to test it and there’s ice that’s sticking out of the box which won’t look good if I use this anywhere players can see so I wanna know how to keep the ice parts from sticking out

Script: ```local frozedparts = {}
local FreezeParts = {}
local module = require(game.ReplicatedStorage.lotsoffunstuff)

local function func(v, vec)
if vec and v then
local newpart = Instance.new(“Part”, workspace)
newpart.Color = script.Parent.Color
newpart.Name = “FreezePart”
for i,v in pairs(script.icedecals:GetChildren()) do
local clon = v:Clone()
clon.Parent = newpart
end
newpart.Color = Color3.fromRGB(4, 175, 236)
newpart.Material = “SmoothPlastic”
newpart.CanCollide = false
newpart.Transparency = 0.7

	local ray = RaycastParams.new()
	ray.IgnoreWater = true
	ray.FilterType = Enum.RaycastFilterType.Exclude
	ray.FilterDescendantsInstances = {script.Parent, FreezeParts, frozedparts}
	local realray = workspace:Raycast(script.Parent.Position, vec * 50, ray)

	if realray then
		local partthing = realray.Instance
		if partthing then
			local hum = module.FindHumanoid(partthing.Parent)
			if not hum then
				if partthing.Locked == false then
					table.insert(frozedparts, partthing)
					newpart.CFrame = CFrame.new(realray.Position, realray.Position + realray.Normal)
					if (script.Parent.Position - newpart.Position).Magnitude <= 20 then
						table.insert(FreezeParts,newpart)
						newpart.Orientation = partthing.Orientation
						local SizeX = math.clamp(newpart.Size.X, partthing.Size.X - partthing.Size.X/2, partthing.Size.X + partthing.Size.X/2)
						local SizeZ = math.clamp(newpart.Size.Z, partthing.Size.Z - partthing.Size.Z/2, partthing.Size.Z + partthing.Size.Z/2)
						local SizeY = math.clamp(newpart.Size.Y, partthing.Size.Y - partthing.Size.Y/2, partthing.Size.Y + partthing.Size.Y/2)

						local fitvector =  Vector3.new(SizeX, SizeY, SizeZ)

						if partthing.Size.X > 20 or partthing.Size.Y > 20 or partthing.Size.Z > 20 then
							newpart.Size = fitvector * Vector3.new(0.8,0.8,0.8)
						else
							newpart.Size = fitvector
						end 
					else
						newpart:Destroy()
					end
				end
			end
		end
	end

	newpart.Anchored = true
end

end

wait(5)
script.Parent.ice_shatter:Play()
for i,v in pairs(workspace:GetChildren()) do
if v ~= script.Parent then
if v:IsA(“Part”) then
local magnitude = (script.Parent.Position - v.Position).Magnitude
if magnitude <= 50 then
func(v, script.Parent.CFrame.RightVector.Unit)
func(v, -script.Parent.CFrame.RightVector.Unit)
func(v, script.Parent.CFrame.UpVector.Unit)
func(v, -script.Parent.CFrame.UpVector.Unit)
func(v, script.Parent.CFrame.LookVector.Unit)
func(v, -script.Parent.CFrame.LookVector.Unit)
end
end
end
end```