TopBar module - Brings back the TopBar frame from ~May 2015-March 2020

Hello,

I’ve made a simple module to bring back the TopBar frame that existed from around May 2015 up until March 2020, when Roblox updated the Core UI. The module link is here, and if you don’t want to go to the Roblox library to buy it, you can just copy-paste this code:

--[[

// pos0
// 1/11/22
// TopBarScript
// Brings back the old TopBar that existed up until March 2020 (source: https://devforum.roblox.com/t/new-in-game-topbar/480226).
// This does not bring back the Settings, Chat, Playerlist, Backpack, or Health GUIs. If you want those, check this out:
// https://github.com/p0s0/ob-framework

// DOCUMENTATION:
	// topBar:Create(instance, props)
		// Variables:
			// instance: Valid instance to create
			// props: Table
		// Description: Creates a new Instance with properties according to the props table
		// Returns: The new instance, or false on failure.
		// Example use case: topBar:Create("BoolValue", 
			Name = "Hi";
			Value = true;
			Parent = workspace;
		);
	// getTransparencyValue(newTransparency)
		// Variables:
			// newTransparency: number
		// Description: Internal function to get the transparency value to be set when topBar:UpdateTopBarTransparency() is called. I promise it isn't useless.
		// Returns: The transparency that is computed
		// Example use case: getTransparencyValue(0.5)
	// topBar:UpdateTopBarTransparency(newTransparency)
		// Variables:
			// newTransparency: number
		// Description: Updates the top bar transparency.
		// Returns: True on success, false on failure.
		// Example use case: topBar:UpdateTopBarTransparency(0.5)
	// topBar:ToggleTopBar()
		// Description: Toggles the top bar on/off.
		// Returns: True on success, false on failure.
		// Example use case: topBar:ToggleTopBar()
	// topBar:ChangeTopBarThickness(newThickness)
		// Variables:
			// optional newThickness: number
		// Description: Changes the top bar thickness. Default is 36.
		// Returns: True on success, false on failure.
		// Example use case: topBar:ChangeTopBarThickness(72)
	// topBar:StartTopBar(parent)
		// Variables:
			// parent: Instance
		// Description: Starts the top bar engine.
		// Returns: True on success, false on failure.
		// Example use case: topBar:StartTopBar(script.Parent)
--]]

local topBar = {}
local TopbarConstants = {
	TOPBAR_THICKNESS = 36,
	TOPBAR_BACKGROUND_COLOR = Color3.new(31/255,31/255,31/255),
	TOPBAR_OPAQUE_TRANSPARENCY = 0,
	TOPBAR_TRANSLUCENT_TRANSPARENCY = 0.5,
	TOPBAR_STARTED = false,
	TOPBAR_DISABLED = false
}

local topbarContainer = nil
local topbarShadow = nil
local topbarChangedEvent = nil

function topBar:Create(instance, props)
	local newInstance
	local success, err = pcall(function()
		newInstance = Instance.new(instance)
	end)
	
	if success then
		for v,i in pairs(props) do
			newInstance[v] = i
		end
		
		return newInstance
	else
		warn(string.format("There was an error whilst creating new Instance %s: %s", tostring(instance), tostring(err)))
		return false
	end
end

function getTransparencyValue(newTransparency)
	if not TopbarConstants.TOPBAR_STARTED then warn("The top bar engine is not started, cannot update the transparency of the TopBar.") return false end
	
	if TopbarConstants.TOPBAR_DISABLED then
		return 1
	end
	
	if newTransparency ~= nil then
		return newTransparency
	end
	
	return TopbarConstants.TOPBAR_TRANSLUCENT_TRANSPARENCY
end

function topBar:UpdateTopBarTransparency(newTransparency)
	if not TopbarConstants.TOPBAR_STARTED then warn("The top bar engine is not started, cannot update the transparency of the TopBar.") return false end
	
	topbarContainer.BackgroundTransparency = getTransparencyValue(newTransparency)
	topbarShadow.Visible = (topbarContainer.BackgroundTransparency == 0)
	
	return true
end

function topBar:ToggleTopBar()
	if not TopbarConstants.TOPBAR_STARTED then warn("The top bar engine is not started, cannot toggle the TopBar.") return false end
	
	TopbarConstants.TOPBAR_DISABLED = not TopbarConstants.TOPBAR_DISABLED
	topBar:UpdateTopBarTransparency()
	
	return true
end

function topBar:ChangeTopBarThickness(newThickness)
	if not TopbarConstants.TOPBAR_STARTED then warn("The top bar engine is not started, cannot change the thickness of the TopBar.") return false end
	if newThickness == nil then newThickness = 36 end
	
	topbarContainer.Size = UDim2.new(1, 0, 0, newThickness)
	topbarContainer.Position = UDim2.new(0, 0, 0, -newThickness)
	TopbarConstants.TOPBAR_THICKNESS = newThickness
	
	return true
end

function topBar:StartTopBar(parent)
	if TopbarConstants.TOPBAR_STARTED then warn("The top bar engine is already started!") return false end
	
	topbarContainer = topBar:Create('Frame', {
		Name = "TopBarContainer";
		Size = UDim2.new(1, 0, 0, TopbarConstants.TOPBAR_THICKNESS);
		Position = UDim2.new(0, 0, 0, (not parent:IsA("ScreenGui") and -TopbarConstants.TOPBAR_THICKNESS or parent:IsA("ScreenGui") and parent.IgnoreGuiInset == true and 0 or -TopbarConstants.TOPBAR_THICKNESS));
		BackgroundTransparency = TopbarConstants.TOPBAR_OPAQUE_TRANSPARENCY;
		BackgroundColor3 = TopbarConstants.TOPBAR_BACKGROUND_COLOR;
		BorderSizePixel = 0;
		Active = true;
		Parent = parent;
	});

	topbarShadow = topBar:Create('ImageLabel', {
		Name = "TopBarShadow";
		Size = UDim2.new(1, 0, 0, 3);
		Position = UDim2.new(0, 0, 1, 0);
		Image = "rbxasset://textures/ui/TopBar/dropshadow.png";
		BackgroundTransparency = 1;
		Active = false;
		Visible = false;
		Parent = topbarContainer;
	});
	
	TopbarConstants.TOPBAR_STARTED = true
	
	topbarChangedEvent = topbarContainer.Changed:Connect(function()
		topBar:UpdateTopBarTransparency(topbarContainer.BackgroundTransparency)
	end)
	
	topBar:UpdateTopBarTransparency()
	
	return true
end

return topBar

To use this module, simply require it from a LocalScript and call StartTopBar(script.Parent). If there’s any missing documentation or anything in general missing/any bugs, let me know.

Thanks,
pos0.

6 Likes

It’s nice!

image
I feel like there should be some padding between the icons and the bottom of the topbar. Other than that pretty cool module!

2 Likes

Sadly, it’s not possible. These are in the CoreGui, which is protected and cannot normally be accessed. You can see what works for you if you change the TOPBAR_THICKNESS in TopbarConstants. The default thickness is 36.

1 Like

I must be dumb, because I don’t know to how make it work!