Problems with custom prompt

so i made a custom prompt. i have 2 problems

  1. my percentage value doesnt really go to 100% when my hold duration has finished for the proximity prompt. sometimes it would be like 98.975825 or something like that. i heard its something to do with a floating number or something? idk

and 2. for my circular progress bar, im trying to make my left_grad’s (ui gradient) rotation to start rotating when the right_grad has finished done so.

if you guys have any idea id really appreciate some help; thanks a million

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 = Progress * 100
		local silvercircleL = PP_UI.holder.left.silverCircle
		local silvercircleR = PP_UI.holder.right.silverCircle
		local left_grad = silvercircleL.UIGradient
		local right_grad = silvercircleR.UIGradient

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

		if Progress >= 1 then
			percentage.Value = 100
			promptCompleted = true
			percentage.Value = 0
			connection:Disconnect()
		end
		
		if Progress >= 0 then
			right_grad.Rotation = math.clamp(Progress * 180, 0, 180)
			right_grad.Color = ColorSequence.new{
				ColorSequenceKeypoint.new(0, PP_UI.holder.colorOfmissingPart.Value),
				ColorSequenceKeypoint.new(0.5, PP_UI.holder.colorOfmissingPart.Value),
				ColorSequenceKeypoint.new(0.501, PP_UI.holder.colorOfProgress.Value),
				ColorSequenceKeypoint.new(1, PP_UI.holder.colorOfProgress.Value),
			}
				right_grad.Transparency = NumberSequence.new(0)
				left_grad.Rotation = math.clamp(180 + (Progress * 180), 180, 360)
				left_grad.Color = ColorSequence.new{
					ColorSequenceKeypoint.new(0, PP_UI.holder.colorOfmissingPart.Value),
					ColorSequenceKeypoint.new(0.5, PP_UI.holder.colorOfmissingPart.Value),
					ColorSequenceKeypoint.new(0.501, PP_UI.holder.colorOfProgress.Value),
					ColorSequenceKeypoint.new(1, PP_UI.holder.colorOfProgress.Value),
				}
				left_grad.Transparency = NumberSequence.new(0)
		end

	end

	connection = rs.RenderStepped:Connect(updatePercentageHeld)

end

pp.PromptButtonHoldBegan:Connect(buttonholdBegan)

So, for the first solution you should use math.floor(number), and could you explain further for the second issue?

2 Likes

No offense but why is that script so unnecessarily long

1 Like

cuz i have no idea what im doing lol

hey king,
thanks for your help once again mate.

for math.floor do you mean for both of these variables or just percentagevalue?

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

so for the second issue, im trying to make my ui like the circle on the bottom left. something like that anyways. it’s just glitching really, it won’t like smoothly rotate.

			right_grad.Rotation = math.clamp(Progress * 180, 0, 180)
			right_grad.Color = ColorSequence.new{
				ColorSequenceKeypoint.new(0, PP_UI.holder.colorOfmissingPart.Value),
				ColorSequenceKeypoint.new(0.5, PP_UI.holder.colorOfmissingPart.Value),
				ColorSequenceKeypoint.new(0.501, PP_UI.holder.colorOfProgress.Value),
				ColorSequenceKeypoint.new(1, PP_UI.holder.colorOfProgress.Value),
			}
				right_grad.Transparency = NumberSequence.new(0)
				
				if right_grad.Rotation >= 180 then
			left_grad.Rotation = math.clamp(180 + (Progress * 180), 180, 360)
			left_grad.Color = ColorSequence.new{
				ColorSequenceKeypoint.new(0, PP_UI.holder.colorOfmissingPart.Value),
				ColorSequenceKeypoint.new(0.5, PP_UI.holder.colorOfmissingPart.Value),
				ColorSequenceKeypoint.new(0.501, PP_UI.holder.colorOfProgress.Value),
				ColorSequenceKeypoint.new(1, PP_UI.holder.colorOfProgress.Value),
			}
			left_grad.Transparency = NumberSequence.new(0)

yes, keep it as you did it, its correct.

could you show me the snippet of the Working rotation script?

1 Like

cheers for clarifying mate.

what i attached there was my rotation script. its the left_grad and right_grad that is rotating.

the right_grad works but the left one goes straight to the top rather than around in a circle. its hard to explain mb :triumph:

local percentage = PP_UI.holder:WaitForChild("percentage")
local startTime = nil
local connection = nil
local promptCompleted = false

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)
		local silvercircleL = PP_UI.holder.left.silverCircle
		local silvercircleR = PP_UI.holder.right.silverCircle
		local left_grad = silvercircleL.UIGradient
		local right_grad = silvercircleR.UIGradient

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

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

local function buttonholdEnded(p)
	print("holding ended")

	if not promptCompleted then
		print("prompt cancelled b4 100%")
	end

	if connection then
		connection:Disconnect()
	end
end
pp.PromptButtonHoldEnded:Connect(buttonholdEnded)

update: i solved it. thank you guys so much for your help :slight_smile:

solution:

local percentage = PP_UI.holder:WaitForChild("percentage")
local startTime = nil
local connection = nil
local promptCompleted = false
local silvercircleL = PP_UI.holder.left.silverCircle
local silvercircleR = PP_UI.holder.right.silverCircle
local left_grad = silvercircleL.UIGradient
local right_grad = silvercircleR.UIGradient

local function resetGradients(left_grad, right_grad)
	left_grad.Rotation = 180
	right_grad.Rotation = 0
	left_grad.Color = ColorSequence.new{
		ColorSequenceKeypoint.new(0, PP_UI.holder.colorOfmissingPart.Value),
		ColorSequenceKeypoint.new(1, PP_UI.holder.colorOfmissingPart.Value)
	}
	right_grad.Color = ColorSequence.new{
		ColorSequenceKeypoint.new(0, PP_UI.holder.colorOfmissingPart.Value),
		ColorSequenceKeypoint.new(1, PP_UI.holder.colorOfmissingPart.Value)
	}
	left_grad.Transparency = NumberSequence.new(0)
	right_grad.Transparency = NumberSequence.new(0)
	percentage.Value = 0
end

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)

local function buttonholdEnded(p)
	print("holding ended")

	if connection then
		resetGradients(left_grad, right_grad)
		connection:Disconnect()
	end
end
pp.PromptButtonHoldEnded:Connect(buttonholdEnded)

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