Problems with Circular progress bar

So I am relatively new to scripting and I am working with a free model circular progress bar gui but I can’t seem to optimize it for what I am trying to do. All of this is kind of confusing, and I’d love to have at least some pointers as to where to look for some info.

This is all for an objective system BTW:

Anyway, this is what I got so far. The max variable is the requirement (the number of wood, logs, etc. you need to complete the objective.) The progress variable is the progress the player has so far on each objective. I’ve tried a few things, and I’ve altered stuff and removed the tweens (as I said before this was from a free model since I had no clue how to make this).

Location:

code: (localscript)

local leftFrame = script.Parent:WaitForChild("LeftBG"):WaitForChild("LeftFrame")
local rightFrame = script.Parent:WaitForChild("RightBG"):WaitForChild("RightFrame")



local numValue = Instance.new("NumberValue")

local max = script.Parent.Parent.completeObj.Value
local progress = script.Parent.Parent.Progress.Value

numValue.Changed:Connect(function()
	
	
	local rightRot = math.clamp(numValue.Value - max,progress , 0)
	
	rightFrame.Rotation = rightRot
	
	
	if numValue.Value <= 180 then
		
		leftFrame.Visible = false
		
		
	else
		
		local leftRot = math.clamp(numValue.Value - 360, -180, 0)
		
		leftFrame.Rotation = leftRot
		
		leftFrame.Visible = true
	end
end)


function progressBar()
	
	numValue.Value = 30

end


progressBar()

1 Like

What is the issue that you are actually experiencing with this?

1 Like

Okay, yeah I forgot to put that. I was playing around with a few values to try and see what would work to show the correct amount of progress.


This is not working because I should have 0 progress on all of the objectives, and it shows as 50 percent completed, and no matter how I change the variables, I can’t get it to show 0.

My goal is just to understand how to do this, since I can’t seem to figure it out, and nothing I found on the WIKI helped much.

1 Like

I missed one part of the script you changed from the tutorial :happy3: hopefully this works! I got rid of the number value and renamed the function more appropriately

local leftFrame = script.Parent:WaitForChild("LeftBG"):WaitForChild("LeftFrame")
local rightFrame = script.Parent:WaitForChild("RightBG"):WaitForChild("RightFrame")


function UpdateProgress()
	local progress = (script.Parent.Parent.Progress.Value / script.Parent.Parent.completeObj.Value) * 360

    local rightRot = math.clamp(progress  - 180,-180, 0)
	
	rightFrame.Rotation = rightRot
	
	
	if progress  <= 180 then
		
		leftFrame.Visible = false
		
	else
		
		local leftRot = math.clamp(progress  - 360, -180, 0)
		
		leftFrame.Rotation = leftRot
		
		leftFrame.Visible = true
	end
end


UpdateProgress()
2 Likes

The progress shows up as 100% complete now, I think we need to switch something around, but what? Also, thank you so much!

Tried printing numvalue during the function, it always comes out as 0 yet the progress seems to be 360

I wanted to post another reply but i edited the last one instead on accident lol… Check my last reply now xd

1 Like

Oh alright, also thank you! It works, but…

I tried changing the value of the progress integer but it kept resetting to 0
It might be from another script but I just checked it, and it shouldn’t do that.

while true do
	for i,v in pairs (game.Players:GetChildren()) do
		local open = v.PlayerGui:WaitForChild("ObjectiveUi").background.background.background.background.background
		local tasksAtHand = open:GetChildren()
		for _,s in pairs (tasksAtHand) do
			if s.Name == "Folder" then
				
			else
				local backend = require(game.ServerScriptService.Modules.backend)
				for ind,val in pairs (backend) do
					if val[4] == "Rocks" then
						open:WaitForChild(ind).Progress.Value = v.statsFolder.Rocks.Value
					elseif val[4] == "Wood" then
						open:WaitForChild(ind).Progress.Value = v.statsFolder.Wood.Value
					elseif val[4] == "Bandits" then
						open:WaitForChild(ind).Progress.Value = v.statsFolder.Bandits.Value
					end
					if val[3] == v.statsFolder.Bandits.Value and val[4] == "Bandits" then
						-- objective complete
					elseif val[3] == v.statsFolder.Rocks.Value and val[4] == "Rocks" then
						-- objective complete
					elseif val[3] == v.statsFolder.Wood.Value and val[4] == "Wood" then
						-- objective complete
					end
				end
			end
		end
		
		
		
	end
	
	wait()
end

This is the other script, and I’m concerned that open:WaitForChild(ind).Progress.Value = v.statsFolder.Bandits.Value would have something to do with it. Not quite sure tho.

Nevermind, I’m an idiot. I changed the wrong value. I realize now the problem is the wheel does not update when I update the values (yes im doing it through the server) sorry

OOP just got it! Wrapped the function call in a while loop!
THANK YOU! Really, but if you don’t mind me asking, how did you determine where to put the variables in math.clamp?
image

Don’t waste resources with while loop xd Just connect the function to that Progress value by script.Parent.Parent.Progress.Changed:Connect(UpdateProgress) at the end of the script.

Well, math.clamp(number, min, max) is just a way to lock a number between two values so the rotation (number) has to be between -180 (min) and 0 (max) for it to work correctly according to the tutorial so that’s how i wrote it

1 Like

Okay so I think you want it to work by changing the Progress Number Value in order to update the gui.

I think something like this makes more sense as it works directly from the progress number value rather than using a hidden value.

local leftFrame = script.Parent:WaitForChild("LeftBG"):WaitForChild("LeftFrame")
local rightFrame = script.Parent:WaitForChild("RightBG"):WaitForChild("RightFrame")

local max = script.Parent.Parent.completeObj
local progress = script.Parent.Parent.Progress

local function onProgressChanged(newValue)
	
	local progressProp = math.clamp(newValue/max.Value, 0, 1)
	rightFrame.Rotation = 180 * progressProp
	
	if progressProp  <= 0.5 then
		leftFrame.Visible = false
	else
		local leftRot = 360 * (progressProp - 1)
		leftFrame.Rotation = leftRot
		leftFrame.Visible = true
	end
end)

local function init()
    onProgressChanged(progress.Value)
    progress.Changed:Connect(onProgressChanged)
end

init()