BitoLog's ProgressBar Thing

BitoLog’s ProgressBar Thing:

image

to use it you need:

  • Place the Module script that you got from the link in StarterPlayerScripts
    • (Its not required to place it exactly there, its just prefered location)
  • require the Module script
  • use .New function on required Module script with Config and Style as a tables

Example script: (for Attribute type; any other type is simular)

local plr = game.Players.LocalPlayer
local PBH = require(plr.PlayerScripts.ProgressBarHandler)

local Config = {
    Type = "Attribute",
	MaxValue = 25,
	ValueName = "Attribute",
	Value = tool,
}
local Style = {
    ProgressBar = {YScale = 1, ...},
    Text = {Text = "Attribute", ...},
    Background = {Color = Color3.new(0,0,0), ...}
}

local Bar = PBH.New(Config, Style)

additional example use: (you can see the result in the fits screenshot)

local PBH = require(game.Players.LocalPlayer.PlayerScripts.ProgressBarHandler)

script:SetAttribute("Attribute", 4)

local Config = {
	Type = "Attribute",
	MaxValue = 10,
	ValueName = "Attribute",
	Value = script,
}

local Style = {
	ProgressBar = {
		YScale = 0.5,
		Color = Color3.new(0.333333, 0, 0.498039),
		Transparency = 0,
		Direction = "Center",
	},
	Text = {
		Text = "BitoLog's ProgressBar Thing",
		TextTransparency = 0.1,
		TextSize = 14,
		Color = Color3.new(1, 1, 1),
		TextAlignment = "Center",
	},
	Background = {
		Color = Color3.new(0, 0, 0),
		Transparency = 0,
	},
}

local bar = PBH.New(Config, Style)

Additionally you can use other function as a

Bar:Hide(Bool) Hides the ui and pauses it/Unhides and unpauses ui if set to false
to pause ui without hiding it you can give the ui “Pause” tag with :AddTag() function on the ui

use Bar:Destroy() to fully remove the bar


All Config and Style settings

Config:

Type = "String" --REQUIRED [Attribute; Property; IntValue; NumberValue.]
MaxValue = number --REQUIRED ; needed to be more than 0; 
--^isnt used in Property if sayd Property isnt a number but still required
ValueName = "String", --REQUIRED in using Attribute or Property as a type
Value = Instance, --REQUIRED for all supported types
--^for IntValue or NumberValue use a IntValue/NumberValue itself
--^^ for Attribute or Property use the the Instance that the Attribute/Property will get the value from
OnCompletionFunction = function() --runs when Bar Compliting its work (aka value >= MaxValue)
--^does not work if type is Property and if sayd Property isnt a number
OnUpdate = function() --runs every time when Value get updated

Module script will pass Ui to OnCompletionFunction and OnUpdate functions
but additionally Modulescript will pass Percent to OnUpdate function

Example:

OnCompletionFunction = function(ui)
	ui.Bar.BackgroundColor3 = Color3.new(1,0,0)
	--turns the Bar color to red when compliting
    --things that this function do is permanent if OnUpdate function wasnt provided
end,

OnUpdate = function(ui, percent)
	ui.Bar.BackgroundColor3 = Color3.new(percent)
	--sets the Bar color to percent value
end,

Style:

ProgressBar:

YScale = number --from 0 to 1; used for Y Scale in ProgressBar
Color = Color3 -- Used for BackgroundColor3 in ProgressBar
Transparency = number --from 0 to 1; BackgroundTransparency in ProgressBar duh
Direction = "String" --[LeftToRight; RightToLeft; FromCenter] you can add custom Directions
--by adding new value in "ProgressBarDirection"
--for example: ["LeftToRight"] = {Vector2.new(0,0.5), UDim2.new(0,0,0.5,0)}
--^(1st value must be vector2 used for AnchorPoint; 2nd must be UDim2 used for Position)

Text:

Text = "String" --Basic Text for TextLable
TextTransparency = number --from 0 to 1
TextSize = number
TextScale = boolean -- will overwrite TextSize  if set to true
TextAlignment = "String" --uses Roblox's basic TextXAlignment [Center; Left; Right.]
Color = Color3 -- you can use RichText formating

TextType = "String" --[Static; Percent; Dynamic.]
--v required for Dynamic TextType
DynamicType = "String" --[Attribute; Property] works like Type in a config table
ValueName = "String",
Value = Instance,
--v required for PercentTextType
PercentOpener = "String"
PercentCloser = "String"
--Text.." "..PercentOpener..Percent..PercentCloser

Background:

Color = Color3 -- used for BackgroundColor3 in Background ui
Transparency = number -- from 0 to 1; used for BackgroundTransparencyin Background ui

Planned:
Add Bar:SetStyle() function


Heres the module:
--[[ 
	= BitoLog's ProgressBar Thing =
	For documentation see: https://devforum.roblox.com/t/bitologs-progressbar-thing/4850007
]]

local _Debug = true

local plr = game.Players.LocalPlayer

local ProgressBar = {}

local ProgressBarMethods = {}
ProgressBarMethods.__index = ProgressBarMethods

local Gui = nil
local TempUi = nil

local StandartStyle = {
	ProgressBar = {
		YScale = 0.65,
		Color = Color3.new(1, 1, 1),
		Transparency = 0,
		Direction = "LeftToRight",
	},
	Text = {
		Text = "",
		TextTransparency = 0,
		TextSize = 20,
		TextAlignment = "Center",
		Color = Color3.new(0.5,0,1),
		
		TextType = "Static",
		PercentOpener = "",
		PercentCloser = "",
		Value = nil,
		ValueName = "",
	},
	Background = {
		Color = Color3.new(0,0,0),
		Transparency = 0,
	},
}

local ProgressBarDirection = {
	["LeftToRight"] = {Vector2.new(0,0.5), UDim2.new(0,0,0.5,0)},
	["RightToLeft"] = {Vector2.new(1,0.5), UDim2.new(1,0,0.5,0)},
	["FromCenter"] = {Vector2.new(0.5,0.5), UDim2.new(0.5,0,0.5,0)},
}

function ProgressBar.New(Config:{}, Style:{})
	if not Gui or not TempUi then error("Module wasnt initialized, please refer to documentation for the init script") return end
	
	if typeof(Config) ~= "table" then if _Debug then warn("Provided Config isn't a table") end return end
	if typeof(Config.Type) ~= "string" then if _Debug then warn("Provided Type isn't a string") end return end
	if typeof(Config.MaxValue) ~= "number" then if _Debug then warn("Provided MaxValue isn't a number") end return end
	if Config.MaxValue <= 0 then if _Debug then warn("Provided MaxValue must be greater than 0") end return end
	if Config.OnCompletionFunction and typeof(Config.OnCompletionFunction) ~= "function" then if _Debug then warn("\"OnCompletionFunction\" is not a function") end return end
	if Config.OnUpdate and typeof(Config.OnUpdate) ~= "function" then if _Debug then warn("\"OnUpdate\" is not a function") end return end
	
	if Config.Type == "Attribute" or Config.Type == "Property" then
		if not Config.ValueName or typeof(Config.ValueName) ~= "string" then if _Debug then warn("\"ValueName\" is nil or not a string") end return end
		if typeof(Config.Value) ~= "Instance" then if _Debug then warn("Provided Value isn't a Instance") end return end
	elseif Config.Type == "IntValue" or Config.Type == "NumberValue" then
		if typeof(Config.Value) ~= "Instance" then if _Debug then warn("Provided Value isn't a Instance") end return end
	else if _Debug then warn(string.format("Type: \"%s\" is not supported", tostring(Config.Type))) end return end
	
	if Style ~= nil and typeof(Style) ~= "table" then if _Debug then warn("Provided Style isn't a table") end return end
	if not Style or next(Style) == nil then Style = StandartStyle else 
	if Style.ProgressBar and not Style.ProgressBar.YScale then Style.ProgressBar.YScale = StandartStyle.ProgressBar.YScale end end
	if Style.Text and Style.Text.TextType and Style.Text.TextType == "Dynamic" then
		if not Style.Text.Value or typeof(Style.Text.Value) ~= "Instance" then if _Debug then warn("Provided Value isn't a Instance") end return end
		if not Style.Text.ValueName or typeof(Style.Text.ValueName) ~= "string" then if _Debug then warn("\"ValueName\" is nil or not a string") end return end
		if not Style.Text.DynamicType or typeof(Style.Text.DynamicType) ~= "string" then if _Debug then warn("\"DynamicType\" is nil or not a string") end return end
	end
	
	local InternalConfig = table.clone(Config)
	
	local self = setmetatable({
		Config = InternalConfig,
		Style = Style,
		UpdateConnection = nil,
		TextConnection = nil,
		Ui = TempUi:Clone()
	}, ProgressBarMethods)
	
	self.Ui.Parent = Gui.MainFrame
	self.Ui.Name = InternalConfig.Value.Name
	
	self:UpdateStyle()
	
	if InternalConfig.Type == "Attribute" then
		self.UpdateConnection = InternalConfig.Value:GetAttributeChangedSignal(InternalConfig.ValueName):Connect(function() self:Update() end)
	elseif InternalConfig.Type == "Property" then
		self.UpdateConnection = InternalConfig.Value:GetPropertyChangedSignal(InternalConfig.ValueName):Connect(function() self:Update() end)
	elseif InternalConfig.Type == "IntValue" or InternalConfig.Type == "NumberValue" then
		self.UpdateConnection = InternalConfig.Value:GetPropertyChangedSignal("Value"):Connect(function() self:Update() end)
	end
	
	if Style.Text.TextType == "Dynamic" then
		self.TextConnection = self.Style.Text.Value:GetAttributeChangedSignal(self.Style.Text.ValueName):Connect(function() self:Update() end)
	end
	
	self:Update()
	
	return self
end

function ProgressBarMethods:Destroy()
	if self.UpdateConnection then self.UpdateConnection:Disconnect() self.UpdateConnection = nil end
	if self.TextConnection then self.TextConnection:Disconnect() self.TextConnection = nil end
	if self.Ui then self.Ui:Destroy() self.Ui = nil end
	if self.Config then self.Config = nil end
	if self.Style then self.Style = nil end
end

function ProgressBarMethods:Hide(Hide)
	if Hide then
		self.Ui.Parent = script.Hide
		self.Ui:AddTag("Pause")
	else
		self.Ui.Parent = Gui.MainFrame
		self.Ui:RemoveTag("Pause")
		self:Update()
	end
end

function ProgressBarMethods:Update()
	if self.Ui:HasTag("Pause") then if _Debug then print("Ui is Paused; use \"self:Hide(false)\" to unpause") end return end
	
	local a = 0
	local b = self.Config.MaxValue
	if self.Config.Type == "Attribute" then
		a = self.Config.Value:GetAttribute(self.Config.ValueName)
	elseif self.Config.Type == "Property" then
		a = self.Config.Value[self.Config.ValueName]
		if typeof(a) ~= "number" then a = 1 end
	elseif self.Config.Type == "IntValue" or self.Config.Type == "NumberValue" then
		a = self.Config.Value.Value
	end
	local Percent = math.min(1, math.clamp(a,0,math.huge)/b)
	
	local Y = StandartStyle.ProgressBar.YScale
	if self.Style.ProgressBar and self.Style.ProgressBar.YScale then Y = self.Style.ProgressBar.YScale end
	self.Ui.Bar.Size = UDim2.new(Percent,0,math.clamp(Y,0,1),0)
	
	if Percent >= 1 and self.Config.OnCompletionFunction ~= nil then
		self.Config.OnCompletionFunction(self.Ui)
		self.Config.OnCompletionFunction = nil
	end
	
	if self.Config.OnUpdate ~= nil then
		self.Config.OnUpdate(self.Ui, Percent)
	end
	
	local _newText = self.Style.Text.Text
	if self.Style.Text.TextType == "Static" then
	elseif self.Style.Text.TextType == "Percent" then
		_newText = _newText.." "..(self.Style.Text.PercentOpener or StandartStyle.Text.PercentOpener)..string.sub(tostring(Percent*100),0,4)..(self.Style.Text.PercentCloser or StandartStyle.Text.PercentCloser)
	elseif self.Style.Text.TextType == "Dynamic" then
		if self.Style.Text.DynamicType == "Attribute" then
			_newText = _newText.." "..(self.Style.Text.Value:GetAttribute(self.Style.Text.ValueName) or "")
		elseif self.Style.Text.DynamicType == "Property" then
			_newText = _newText.." "..(tostring(self.Style.Text.Value[self.Style.Text.ValueName]) or "")
		else
			if _Debug then
				warn(string.format("Your \"DynamicType\" (%s) isn't supported; please read documentation or ReadMe file", self.Style.Text.DynamicType))
			end
		end
	end
	self.Ui.TextLabel.Text = _newText
end

function ProgressBarMethods:UpdateStyle()
	local Style = self.Style
	local Ui = self.Ui
	
	if Style.ProgressBar then
		Ui.Bar.BackgroundColor3 = Style.ProgressBar.Color or StandartStyle.ProgressBar.Color
		Ui.Bar.BackgroundTransparency = Style.ProgressBar.Transparency or StandartStyle.ProgressBar.Transparency
		if ProgressBarDirection[Style.ProgressBar.Direction] ~= nil then
			local PBD = ProgressBarDirection[Style.ProgressBar.Direction]
			Ui.Bar.AnchorPoint = PBD[1]
			Ui.Bar.Position = PBD[2]
		else
			local PBD = ProgressBarDirection.LeftToRight
			Ui.Bar.AnchorPoint = PBD[1]
			Ui.Bar.Position = PBD[2]
		end
	end
	
	if Style.Text then
		Ui.TextLabel.Text = Style.Text.Text or StandartStyle.Text.Text
		Ui.TextLabel.TextTransparency = Style.Text.TextTransparency or StandartStyle.Text.TextTransparency
		if Style.Text.TextScale ~= nil and Style.Text.TextScale == true then
			Ui.TextLabel.TextScaled = true
		else
			Ui.TextLabel.TextSize = Style.Text.TextSize or StandartStyle.Text.TextSize
		end
		Ui.TextLabel.TextXAlignment = Style.Text.TextAlignment or StandartStyle.Text.TextAlignment
		Ui.TextLabel.TextColor3 = Style.Text.Color or StandartStyle.Text.Color
	end
	
	if Style.Background then
		Ui.BackgroundColor3 = Style.Background.Color or StandartStyle.Background.Color
		Ui.BackgroundTransparency = Style.Background.Transparency or StandartStyle.Background.Transparency
	end
end

function ProgressBar.Init(PBUi, TempBar)
	Gui = PBUi
	TempUi = TempBar
	if _Debug then print("Got Ui", Gui, TempUi) end
	
	if _Debug then print("Initializing \"ProgressBarHandler\"") end
	Gui.Parent = plr.PlayerGui
end

return ProgressBar

and a Init script:

if not game:IsLoaded() then game.Loaded:Wait() end

local PBUi = Instance.new("ScreenGui")
PBUi.IgnoreGuiInset = true
PBUi.Name = "ProgressBarUi"
PBUi.Parent = script.Parent

local MF = Instance.new("Frame")
MF.Name = "MainFrame"
MF.Size = UDim2.new(0.08,0,0.2,0)
MF.Position = UDim2.new(0.5,0,0.65,0)
MF.AnchorPoint = Vector2.new(0.5,0.5)
MF.BackgroundTransparency = 1
MF.Parent = PBUi

local UiList = Instance.new("UIListLayout")
UiList.Padding = UDim.new(0,3)
UiList.Parent = MF

local TempBar = Instance.new("Frame")
TempBar.Name = "TemplateBar"
TempBar.Style = Enum.FrameStyle.Custom
TempBar.BorderSizePixel = 0
TempBar.BackgroundColor3 = Color3.new(1,1,1)
TempBar.Size = UDim2.new(1,0,0.15,0)
TempBar.Parent = script.Parent

local Bar = Instance.new("Frame")
Bar.Name = "Bar"
Bar.Style = Enum.FrameStyle.Custom
Bar.BorderSizePixel = 0
Bar.BackgroundColor3 = Color3.new(1,1,1)
Bar.AnchorPoint = Vector2.new(0.5,0.5)
Bar.Position = UDim2.new(0.5,0,0.5,0)
Bar.Size = UDim2.new(1,0,0.65,0)
Bar.Parent = TempBar

local Text = Instance.new("TextLabel")
Text.Size = UDim2.new(1,0,1,0)
Text.BackgroundTransparency = 1
Text.Parent = TempBar
Text.TextSize = 14

local Hide = Instance.new("Folder")
Hide.Name = "Hide"
Hide.Parent = script.Parent

require(script.Parent).Init(PBUi, TempBar)

Bouth of them is required, place Main module in StarterPlayer.ProgressBarHandler and the init into the module it self


The Module script isnt very tested so if you have any ideas/errors with the module it self/adviсes you can reply to the topic, i will happely help you or add the things that you want
(my english isnt that good, so if you see any tyops turn a blind eye on it please)

3 Likes

can someone tell is the model public? and if not how do i upload it properly?

" We couldn’t find the page you were looking for"

Nope it’s not.

looks neat, but you forgot to put it on sale

god damn it, its so complicated to me uploading that module to free use, im gonna make all set up in init script, i need to re code some things so wait a little please