local g=Vector3.new(3,2.8,3)local R=script.Parent local Z=R.Contents local j=3 function r(g)return math.random(-math.abs(g*100),math.abs(g*100))/100 end R.Base.Touched:connect(function(j)local O if j:FindFirstChild("\068\114\097\103\103\105\110\103")then return end if j:FindFirstChild("\068\114\097\103\103\097\098\108\101")and j:FindFirstChild("\080\105\099\107\117\112")then O=j:Clone()j:Destroy()elseif j.Parent and(j.Parent:FindFirstChild("\068\114\097\103\103\097\098\108\101")and j.Parent:FindFirstChild("\080\105\099\107\117\112"))then O=j.Parent:Clone()j.Parent:Destroy()else return end for g,R in next,O:GetDescendants()do if R.Name=="\068\114\097\103\103\097\098\108\101"then R:Destroy()end end if O:IsA("\066\097\115\101\080\097\114\116")then O.Anchored=true O.CanCollide=false local Z=g-O.Size print(Z,"\097\115 \118\097\114\105\097\110\099\101")O.CFrame=R.PrimaryPart.CFrame*CFrame.new(math.random(-100,100)/100,math.random(100,200)/100,math.random(-100,100)/100)elseif O:IsA("\077\111\100\101\108")then for g,R in next,O:GetDescendants()do if R:IsA("\066\097\115\101\080\097\114\116")then R.Anchored=true R.CanCollide=false end end local Z=O:GetExtentsSize()local j=g-Z O:SetPrimaryPartCFrame(R.PrimaryPart.CFrame*CFrame.new(math.random(-100,100)/100,math.random(100,200)/100,math.random(-100,100)/100))end O.Parent=Z end)
--local freeSpaceX,freeSpaceY,freeSpaceZ = 3,3,2.8
local freeSpace = Vector3.new(3, 2.8, 3)
local box = script.Parent
local contents = box.Contents

local lidOffset = 3

function r(num)
	return math.random(-math.abs(num * 100), math.abs(num * 100)) / 100
end

box.Base.Touched:connect(function(oldHit)
	local hit

	if oldHit:FindFirstChild("Dragging") then
		return
	end

	if oldHit:FindFirstChild("Draggable") and oldHit:FindFirstChild("Pickup") then
		hit = oldHit:Clone()
		oldHit:Destroy()
	elseif oldHit.Parent and (oldHit.Parent:FindFirstChild("Draggable") and oldHit.Parent:FindFirstChild("Pickup")) then
		hit = oldHit.Parent:Clone()
		oldHit.Parent:Destroy()
	else
		return
	end

	for _, child in next, hit:GetDescendants() do
		if child.Name == "Draggable" then
			child:Destroy()
		end
	end

	if hit:IsA("BasePart") then
		hit.Anchored = true
		hit.CanCollide = false
		local vary = freeSpace - hit.Size
		-- random x,y,z
		print(vary, "as variance")
		--hit.CFrame = box.PrimaryPart.CFrame*CFrame.new(r(vary.X),1+math.random(0,vary.Y*100)/100,r(vary.Z))
		hit.CFrame = box.PrimaryPart.CFrame
			* CFrame.new(math.random(-100, 100) / 100, math.random(100, 200) / 100, math.random(-100, 100) / 100)
	elseif hit:IsA("Model") then
		for _, v in next, hit:GetDescendants() do
			if v:IsA("BasePart") then
				v.Anchored = true
				v.CanCollide = false
			end
		end
		local modelSize = hit:GetExtentsSize()
		local vary = freeSpace - modelSize
		--hit:SetPrimaryPartCFrame(box.PrimaryPart.CFrame*CFrame.new(r(vary.X),1+math.random(0,vary.Y*100)/100,r(vary.Z)))
		hit:SetPrimaryPartCFrame(
			box.PrimaryPart.CFrame
				* CFrame.new(math.random(-100, 100) / 100, math.random(100, 200) / 100, math.random(-100, 100) / 100)
		)
	end -- end of if hit is a basepart or model
	hit.Parent = contents
end)
