Cube dimension
Key RequiredUniversal

Cube dimension

Universal ScriptYzn_lolYzn_lol 303 views 278 executesUpdated Feb 7, 2026
5.0/ 5(1 votes)
10100% Positive
Lua Script•332 lines (10219 chars)
--// SERVICES
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local player = Players.LocalPlayer

---------------------------------------------------
-- SETTINGS
---------------------------------------------------
local DIMENSION_POSITION = Vector3.new(0, 0, 50000)
local portal
local returnPortal
local originalPosition
local inCubeDimension = false
local cubeSize = 30
local rotationSpeed = 0.001

-- folder for player-built cubes
local buildFolder = workspace:FindFirstChild("PlayerCubes") or Instance.new("Folder")
buildFolder.Name = "PlayerCubes"
buildFolder.Parent = workspace

---------------------------------------------------
-- GUI
---------------------------------------------------
local gui = Instance.new("ScreenGui")
gui.ResetOnSpawn = false
gui.Parent = player.PlayerGui

local messageLabel = Instance.new("TextLabel")
messageLabel.Size = UDim2.fromOffset(600,50)
messageLabel.Position = UDim2.fromScale(0.5,0.9)
messageLabel.AnchorPoint = Vector2.new(0.5,0.5)
messageLabel.TextScaled = true
messageLabel.BackgroundTransparency = 1
messageLabel.TextColor3 = Color3.new(1,0,0)
messageLabel.Text = ""
messageLabel.Parent = gui

-- PORTAL BUTTON
local portalButton = Instance.new("TextButton")
portalButton.Size = UDim2.fromOffset(150,50)
portalButton.Position = UDim2.fromOffset(30,200)
portalButton.Text = "Create Portal"
portalButton.TextScaled = true
portalButton.BackgroundColor3 = Color3.fromRGB(80,0,120)
portalButton.TextColor3 = Color3.new(1,1,1)
portalButton.Draggable = true
portalButton.Parent = gui

---------------------------------------------------
-- PRELOAD CUBE DIMENSION
---------------------------------------------------
local portalWorld = Instance.new("Folder")
portalWorld.Name = "PreloadedCubeDimension"
portalWorld.Parent = workspace

-- Black cube box
local roomSize = 1000
local function createWall(size, pos)
	local wall = Instance.new("Part")
	wall.Size = size
	wall.Anchored = true
	wall.CanCollide = true
	wall.Material = Enum.Material.SmoothPlastic
	wall.Color = Color3.new(0,0,0)
	wall.Position = pos
	wall.Parent = portalWorld
end

createWall(Vector3.new(roomSize,1,roomSize), DIMENSION_POSITION + Vector3.new(0,-5,0))
createWall(Vector3.new(roomSize,1,roomSize), DIMENSION_POSITION + Vector3.new(0,roomSize/2,0))
createWall(Vector3.new(1,roomSize,roomSize), DIMENSION_POSITION + Vector3.new(-roomSize/2,roomSize/2,0))
createWall(Vector3.new(1,roomSize,roomSize), DIMENSION_POSITION + Vector3.new(roomSize/2,roomSize/2,0))
createWall(Vector3.new(roomSize,roomSize,1), DIMENSION_POSITION + Vector3.new(0,roomSize/2,-roomSize/2))
createWall(Vector3.new(roomSize,roomSize,1), DIMENSION_POSITION + Vector3.new(0,roomSize/2,roomSize/2))

-- Return portal
returnPortal = Instance.new("Part")
returnPortal.Size = Vector3.new(6,8,1)
returnPortal.Material = Enum.Material.Neon
returnPortal.Color = Color3.fromRGB(0,170,255)
returnPortal.Anchored = true
returnPortal.CanCollide = false
returnPortal.Position = DIMENSION_POSITION + Vector3.new(0,5,-40)
returnPortal.Parent = portalWorld

-- Giant RGB cube
local bigCube = Instance.new("Part")
bigCube.Size = Vector3.new(cubeSize*2, cubeSize*2, cubeSize*2)
bigCube.Material = Enum.Material.Neon
bigCube.Anchored = true
bigCube.Position = DIMENSION_POSITION + Vector3.new(0,50,150)
bigCube.Parent = portalWorld

-- RGB cycling
task.spawn(function()
	local hue = 0
	while bigCube.Parent do
		hue = (hue + 0.005) % 1
		bigCube.Color = Color3.fromHSV(hue,1,1)
		RunService.RenderStepped:Wait()
	end
end)

-- Orbiting cubes
local orbitRadius = 60
local smallCubeSize = cubeSize/2
for i = 1, 10 do
	local smallCube = Instance.new("Part")
	smallCube.Size = Vector3.new(smallCubeSize, smallCubeSize, smallCubeSize)
	smallCube.Material = Enum.Material.Neon
	smallCube.Anchored = true
	smallCube.Color = Color3.fromHSV(math.random(),1,1)
	smallCube.Parent = portalWorld

	local angleOffset = (2*math.pi/5) * ((i-1)%5)
	local tilt = (i <= 5) and CFrame.Angles(math.rad(45),0,0) or CFrame.Angles(math.rad(-45),0,0)

	task.spawn(function()
		while smallCube.Parent do
			local t = tick()
			local angle = t + angleOffset
			local localPos = Vector3.new(math.cos(angle)*orbitRadius,0,math.sin(angle)*orbitRadius)
			smallCube.CFrame = CFrame.new(bigCube.Position) * tilt * CFrame.new(localPos) * CFrame.Angles(t*rotationSpeed, t*rotationSpeed, t*rotationSpeed)
			RunService.RenderStepped:Wait()
		end
	end)
end

-- Floating normal cubes
for i = 1,30 do
	local cube = Instance.new("Part")
	cube.Size = Vector3.new(cubeSize,cubeSize,cubeSize)
	cube.Material = Enum.Material.Neon
	cube.Anchored = true
	cube.Color = Color3.fromHSV(math.random(),1,1)
	cube.Parent = portalWorld

	local pos
	repeat
		pos = DIMENSION_POSITION + Vector3.new(
			math.random(-500,500),
			math.random(10,90),
			math.random(-500,500)
		)
	until (pos - returnPortal.Position).Magnitude > 30 and (pos - bigCube.Position).Magnitude > 80

	local rot = 0
	local phase = math.random()*math.pi*2
	task.spawn(function()
		while cube.Parent do
			local t = tick()
			local floatY = math.sin(t*1.5+phase)*6
			rot += rotationSpeed
			cube.CFrame = CFrame.new(pos.X,pos.Y+floatY,pos.Z) * CFrame.Angles(rot,rot,rot)
			RunService.RenderStepped:Wait()
		end
	end)
end

---------------------------------------------------
-- CREATE PORTAL FUNCTION
---------------------------------------------------
local function createPortal()
	if inCubeDimension then return end

	local char = player.Character or player.CharacterAdded:Wait()
	local hrp = char:WaitForChild("HumanoidRootPart")
	if portal then portal:Destroy() end
	originalPosition = hrp.Position

	portal = Instance.new("Part")
	portal.Size = Vector3.new(6,8,1)
	portal.Material = Enum.Material.Neon
	portal.Color = Color3.fromRGB(140,0,255)
	portal.Anchored = true
	portal.CanCollide = false
	portal.CFrame = hrp.CFrame * CFrame.new(0,0,-10)
	portal.Parent = workspace

	portal.Touched:Connect(function(hit)
		if not hit.Parent:FindFirstChild("Humanoid") then return end
		messageLabel.Text = "???: You're not supposed to be here"
		hrp.CFrame = CFrame.new(DIMENSION_POSITION + Vector3.new(0,5,0))
		inCubeDimension = true

		portal:Destroy()
		portal = nil
	end)
end

-- connect GUI button to portal function
portalButton.MouseButton1Click:Connect(createPortal)

---------------------------------------------------
-- RETURN PORTAL CHECK
---------------------------------------------------
RunService.Heartbeat:Connect(function()
	local char = player.Character
	if not char then return end
	local hrp = char:FindFirstChild("HumanoidRootPart")
	if hrp and returnPortal and (hrp.Position - returnPortal.Position).Magnitude < 6 and inCubeDimension then
		if originalPosition then
			hrp.CFrame = CFrame.new(originalPosition + Vector3.new(0,5,0))
		end
		inCubeDimension = false
		messageLabel.Text = ""
	end
end)

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local Workspace = game:GetService("Workspace")

local player = Players.LocalPlayer
local camera = Workspace.CurrentCamera

-- Folder for spawned cubes
local buildFolder = Workspace:FindFirstChild("PlayerCubes") or Instance.new("Folder")
buildFolder.Name = "PlayerCubes"
buildFolder.Parent = Workspace

---------------------------------------------------
-- FUNCTION TO GIVE TOOLS
---------------------------------------------------
local function giveTools()
	-- clear old duplicates
	for _, v in pairs(player.Backpack:GetChildren()) do
		if v.Name == "Spawn Cube" or v.Name == "Destroy Cube" then
			v:Destroy()
		end
	end

	-- SPAWN CUBE TOOL
	local spawnTool = Instance.new("Tool")
	spawnTool.Name = "Spawn Cube"
	spawnTool.RequiresHandle = false
	spawnTool.CanBeDropped = false
	spawnTool.Parent = player.Backpack

	spawnTool.Activated:Connect(function()
		local char = player.Character
		if not char then return end
		local hrp = char:FindFirstChild("HumanoidRootPart")
		if not hrp then return end

		local mouseLocation = UserInputService:GetMouseLocation()
		mouseLocation = Vector2.new(mouseLocation.X, mouseLocation.Y - 36)

		local unitRay = camera:ScreenPointToRay(mouseLocation.X, mouseLocation.Y)
		local ray = Ray.new(unitRay.Origin, unitRay.Direction * 1000)
		local ignoreList = {char}
		local hit, pos = Workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)

		local spawnPos
		if hit then
			spawnPos = pos + Vector3.new(0,15,0)
		else
			spawnPos = hrp.Position + hrp.CFrame.LookVector * 10 + Vector3.new(0,15,0)
		end

		local cube = Instance.new("Part")
		cube.Size = Vector3.new(30,30,30)
		cube.Anchored = true
		cube.Material = Enum.Material.Neon
		cube.Color = Color3.fromHSV(math.random(),1,1)
		cube.Position = spawnPos
		cube.Parent = buildFolder

		local rot = 0
		task.spawn(function()
			while cube.Parent do
				rot += 0.001
				cube.CFrame = CFrame.new(cube.Position) * CFrame.Angles(rot,rot,rot)
				task.wait()
			end
		end)
	end)

	-- DESTROY CUBE TOOL
	local destroyTool = Instance.new("Tool")
	destroyTool.Name = "Destroy Cube"
	destroyTool.RequiresHandle = false
	destroyTool.CanBeDropped = false
	destroyTool.Parent = player.Backpack

	destroyTool.Activated:Connect(function()
		local char = player.Character
		if not char then return end

		local mouseLocation = UserInputService:GetMouseLocation()
		mouseLocation = Vector2.new(mouseLocation.X, mouseLocation.Y - 36)

		local unitRay = camera:ScreenPointToRay(mouseLocation.X, mouseLocation.Y)
		local ray = Ray.new(unitRay.Origin, unitRay.Direction * 1000)
		local ignoreList = {char}
		local hitPart = Workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)

		if hitPart and hitPart.Parent == buildFolder then
			hitPart:Destroy()
		end
	end)
end

-- GIVE TOOLS
giveTools()

-- GIVE TOOLS AGAIN ON RESPAWN
player.CharacterAdded:Connect(function()
	task.wait(0.2) -- wait for backpack to load
	giveTools()
end)

-- Reset state on respawn
player.CharacterAdded:Connect(function(char)
	inCubeDimension = false
	originalPosition = nil

	-- Destroy any leftover portal
	if portal then
		portal:Destroy()
		portal = nil
	end

	-- Destroy path line if it exists
	if pathLine then
		pathLine:Destroy()
		pathLine = nil
	end
end)

Features & Information

How did we get here?

Community Comments (1)

jwlkwgmjwlkwgmSep 25, 2026

Cool

More Scripts for Universal Scripts