Mobile ProximityPrompt

Hello Guys, i need a little Help with my custom Proximity Prompt script.

I have coded a custum BillBoardGUI thats a Custom Proximity prompt and everything is working but i have a small problem:
I have no Idea how i can make the BillBoardGUI work for Mobile and Console Players because you cannot press it and when i turn the “Button” ( its a TextLabel ) into a real TextButton its just buggin around like only taking a Second and not triggering the Prompt so i need a bit help how to fix it.

Here is my LocalScript i am using:

local suffixes = {'','K','M','B','T','qd','Qn','sx','Sp','O','N','de','Ud','DD','tdD','qdD','QnD','sxD','SpD','OcD','NvD','Vgn','UVg','DVg','TVg','qtV','QnV','SeV','SPG','OVG','NVG','TGN','UTG','DTG','tsTG','qtTG','QnTG','ssTG','SpTG','OcTG','NoAG','UnAG','DuAG','TeAG','QdAG','QnAG','SxAG','SpAG','OcAG','NvAG','CT'}

local function format(val)
	for i = 1, #suffixes do
		if tonumber(val) < 10^(i*3) then
			return math.floor(val / ((10^((i-1)*3)) / 100)) / 100 .. suffixes[i]
		end
	end
end

local PromptGui = script.Parent
local Button = PromptGui.Button
local Progress = Button.Progress
local TS = game.TweenService
local CurrentTween
local HoldStartTime
local HoldDuration
local CountdownConnection

PromptGui.Enabled = false

function SetupProximityPrompt(ProximityPrompt)
	-- When the prompt is shown
	ProximityPrompt.PromptShown:Connect(function()
		PromptGui.Enabled = true
		PromptGui.Adornee = ProximityPrompt.Parent
		Button.Text = ProximityPrompt.KeyboardKeyCode.Name
	end)

	-- When the prompt is hidden
	ProximityPrompt.PromptHidden:Connect(function()
		PromptGui.Enabled = false
		PromptGui.Adornee = nil
		if CountdownConnection then
			CountdownConnection:Disconnect()
		end
		-- Reset the progress and text
		Progress.Size = UDim2.new(0, 0, 1, 0)
		Button.Text = ProximityPrompt.KeyboardKeyCode.Name
	end)

	-- When the button hold begins
	ProximityPrompt.PromptButtonHoldBegan:Connect(function()
		HoldStartTime = tick()

		-- Set HoldDuration dynamically based on player's value or other factors
		HoldDuration = ProximityPrompt.HoldDuration  -- This is dynamically set, ensure this is updated properly

		-- Start updating the countdown and progress constantly
		CountdownConnection = game:GetService("RunService").Heartbeat:Connect(function()
			-- Recalculate elapsed time
			local elapsed = tick() - HoldStartTime

			-- Update HoldDuration dynamically if needed (for example, based on player data)
			HoldDuration = ProximityPrompt.HoldDuration  -- Ensure you're recalculating dynamically

			-- Calculate remaining time based on elapsed time and dynamic HoldDuration
			local remaining = math.max(HoldDuration - elapsed, 0)
			Button.Text = format(remaining) -- Display the formatted remaining time

			-- Update progress bar
			-- Calculate the progress as the ratio of elapsed time over the dynamic HoldDuration
			local progress = elapsed / HoldDuration
			Progress.Size = UDim2.new(math.min(progress, 1), 0, 1, 0)  -- Ensure progress doesn't exceed 100%

			-- Stop updating if time runs out
			if remaining <= 0 then
				CountdownConnection:Disconnect()
				Progress.Size = UDim2.new(1, 0, 1, 0) -- Full progress when time is up
			end
		end)
	end)

	-- When the button hold ends
	ProximityPrompt.PromptButtonHoldEnded:Connect(function()
		if CountdownConnection then
			CountdownConnection:Disconnect()
		end
		Progress.Size = UDim2.new(0, 0, 1, 0) -- Reset the progress bar size
		Button.Text = ProximityPrompt.KeyboardKeyCode.Name
	end)
end

-- Set up existing ProximityPrompts in the workspace
for i, v in pairs(game.Workspace:GetDescendants()) do
	if v:IsA("ProximityPrompt") then
		SetupProximityPrompt(v)
	end
end

-- Set up new ProximityPrompts when added
game.Workspace.DescendantAdded:Connect(function(Child)
	if Child:IsA("ProximityPrompt") then
		SetupProximityPrompt(Child)
	end
end)

I hope someone can help me :slight_smile:

1 Like

You have to connect the button to InputHoldBegin and InputHoldEnded

1 Like

Its not working. I already connected it but its like not possible to put console, mobile and Pc togehter. Every time one works the other one doesnt work anymore

1 Like