My percentage value prints less than 100 when holding for prompt has finished

i have 2 variables Progress and percentageValue. progress is 0-1 (representing 0-100%) and percentage value which is also the same thing more less.

my issue is that even after the hold duration has finished for the prompt, it’s meant to print 1 for progress and 100 for percentagevalue. it’s printing something around 98-99 ish when it has completed.

i appreciate any help ty!!

output:
image

video:

local function buttonholdBegan(p)
	print("started holding")
	startTime = tick()
	promptCompleted = false

	local function updatePercentageHeld()
		local elapsedTime = tick() - startTime
		
		local Progress = math.clamp(elapsedTime / TWEEN_TIME, 0, 1) --0 to 100%
		local percentageValue = math.floor(Progress * 100)

		percentage.Value = percentageValue
		print("percentageValue: "..percentageValue)
		print("Progress: "..Progress)

		if Progress >= 1 then
			promptCompleted = true
			percentage.Value = 0
			resetGradients(left_grad, right_grad)
			connection:Disconnect()
		end
		
			right_grad.Rotation = math.clamp(Progress * 360, 0, 180)
			right_grad.Color = ColorSequence.new{
			ColorSequenceKeypoint.new(0, PP_UI.holder.colorOfProgress.Value),
			ColorSequenceKeypoint.new(0.5, PP_UI.holder.colorOfProgress.Value),
			ColorSequenceKeypoint.new(0.501, PP_UI.holder.colorOfmissingPart.Value),
			ColorSequenceKeypoint.new(1, PP_UI.holder.colorOfmissingPart.Value),
			}
			right_grad.Transparency = NumberSequence.new(0)
		if Progress >= 0.5 then
			local leftProgress = (Progress - 0.5) * 2
			left_grad.Rotation = math.clamp(180 + (leftProgress * 180), 180, 360)
			left_grad.Color = ColorSequence.new{
				ColorSequenceKeypoint.new(0, PP_UI.holder.colorOfProgress.Value),
				ColorSequenceKeypoint.new(0.5, PP_UI.holder.colorOfProgress.Value),
				ColorSequenceKeypoint.new(0.501, PP_UI.holder.colorOfmissingPart.Value),
				ColorSequenceKeypoint.new(1, PP_UI.holder.colorOfmissingPart.Value),
			}
			left_grad.Transparency = NumberSequence.new(0)
		end
	end
	connection = rs.RenderStepped:Connect(updatePercentageHeld)
end
pp.PromptButtonHoldBegan:Connect(buttonholdBegan)

Maybe try Heartbeat instead of RenderStepped? I don’t really know what else to suggest

1 Like

hey man, any suggestion helps me honestly.

i tried heartbeat there but unfortunately its giving 98 ish consistently but i really appreciate the help mate ty
image

1 Like

You might have precision issues so just in case use os.clock over tick. Otherwise, idk what else might be wrong

2 Likes

that seems to have done the trick tbh.

it still prints out like 99% ish very rarely but its more less printing 100 bang on. i also changed from renderstepped to stepped and that seemed to have helped as well.

thank you so much for your help killer, you’re a legend mate!!! :slight_smile:

Glad to hear it worked for you but I’ll address why it’s probably 99% sometimes. This is because the event fires every new frame. The time taken before the old frame and the new frame before your event fires is what’s causing the time difference but hey its close enough :person_shrugging:

1 Like

oh yeah i get what u mean. its like a slight delay between old and new frames kind of way.

thanks so much for clarifying!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.