How to add holdDuration to a custom proximity prompt

Hello. I used a youtube video to create this custom prompt, however it only works if the hold duration is 0. I think I need to add something to show the progress of the delay, but I don’t know what I have to name it or the specific way I would have to make it for it to work.
local script:

proximityPrompts.PromptShown:Connect(function(prompt)
	prompt.BillboardGui.Enabled = true
end)

proximityPrompts.PromptHidden:Connect(function(prompt)
	prompt.BillboardGui.Enabled = false
end)

image
please help

You’ll want to utilized the Triggered event. It automatically detects if the player held the prompt for the HoldDuration. This way it should work even if the HoldDuration is higher than 0

ProximityPrompt.Triggered:Connect(function()
 -- do stuff
end)

I’m not sure if i messed it up the first time but it works now, thanks. However, I would like to be able to make a progress bar of sorts to show how long there is. Is there a way to integrate it with the roblox ProximityPrompt scripts or do I have to add it in manually?

You can accomplish this for sure. To do this I’d utilize PromptButtonHoldBegan and PromptButtonHoldEnded

An example:

local holdStart = 0
local holding = false
local holdTime = proximityPrompt.HoldDuration
proximityPrompt.PromptButtonHoldBegan:Connect(function()
    holding = true
    local holdStart = tick() -- record the time when holding started
end)
proximityPrompt.PromptButtonHoldEnded:Connect(function()
    holding = false
end)
-- Use Runservice to monitor the hold statuses and update the bar
game:GetService("RunService"):Connect(function()
    if holding == true then
        -- get the progress and apply it to the bar
        -- use math.clamp to keep the number constrained
        local progress = math.clamp(tick() - holdStart, 0, holdStart)
        progressBar.Size = UDim2.new(progress / holdstart, 0, 1, 0)
    else
        -- when holding is false, the bar is empty
        progressBar.Size = UDim2.new(0, 0, 1, 0)
    end
end)
2 Likes