ProximityPromptService issues

I’m making an interaction system using PPS and a custom UI, and the issue I’m experiencing is that sometimes the UI will create a duplicate of itself when it shouldn’t. (all prompts are set to one per button).

Example screenshot of the issue (ignore the side ui):

Client code:

-- // Get all required services before starting

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ProximityPromptService = game:GetService("ProximityPromptService")

local UserInputService = game:GetService("UserInputService")

local RunService = game:GetService("RunService")

local Players = game:GetService("Players")

local Player = Players.LocalPlayer

local Prompts = ReplicatedStorage.Interface.Interactions

-- // Get all Player GUI objects

local PlayerGui = Player:WaitForChild("PlayerGui")

local RemoteEvent = ReplicatedStorage.Common.Events.RemoteEvent

local RemoteFunction = ReplicatedStorage.Common.Events.Interaction

local InteractionGui = PlayerGui:WaitForChild("InteractionSystem")

--[object] = {[prompt] = billboard, [prompt] = billboard}

-- // Main Code

--// setup prompts




local colors = {Color3.fromRGB(255,255,255), Color3.fromRGB(255, 105, 105)} -- [1]=enabled [2]=disabled

function vp(p) return p.Style == Enum.ProximityPromptStyle.Custom end

function getCurrentPrompts(prompt)

    local t = {}

    for i,v in pairs(prompt.Parent:GetChildren()) do

        if v:IsA("BillboardGui") then

            table.insert(t, v)

        end

    end

    return t

end

ProximityPromptService.PromptShown:Connect(function(prompt)

    if vp(prompt) then

        print('possum shown')

        local details = RemoteFunction:InvokeServer('PromptInfo', prompt)

        local num = #getCurrentPrompts(prompt) + 1

        local UIClone = Prompts['Prompt'..tostring(num)]:Clone()

        UIClone.Parent = prompt.Parent

        UIClone.Enabled = true

        local b = Instance.new('ObjectValue')

        b.Parent = UIClone

        b.Name = 'prompt'

        b.Value = prompt

        local key = UserInputService:GetStringForKeyCode(prompt.KeyboardKeyCode)

        local action = details.ActionText

        UIClone.action.Text = action

        UIClone.Frame.key.Text = key

        if not details.Validation then

            UIClone.action.TextColor3 = colors[2]

        end

        if details.ShowSidebar and details.Validation then

            local Clone2 = Prompts.InteractionFrame:Clone()

            Clone2.Parent = InteractionGui.List

            local j = Instance.new('ObjectValue')

            j.Parent = Clone2

            j.Value = prompt

            j.Name = 'prompt'

            Clone2.action.Text = action

            Clone2.Frame.key.Text = key

        end

    end

end)

ProximityPromptService.PromptHidden:Connect(function(prompt)

    --// Remove the prompt's visible objectvalue

    if vp(prompt) then

        for i,v in pairs(getCurrentPrompts(prompt)) do

            wait()

            local m = v:FindFirstChild('prompt')

            if m then

                if m.Value == prompt then

                    v:Destroy()

                end

            end

        end

        for i,v in pairs(InteractionGui.List:GetChildren()) do

            wait()

            local x = v:FindFirstChild('prompt')

            if x then

                if x.Value == prompt then

                    x:Destroy()

                    v:Destroy()

                end

            end

        end

        print('possum hidden')

    end

end)

ProximityPromptService.PromptTriggered:Connect(function(prompt)

    if vp(prompt) then

        if RemoteFunction:InvokeServer('validate', prompt) then

            RemoteFunction:InvokeServer('execute', prompt)

            --// refresh the prompt to accomodate for any changes

            prompt.Enabled = false

            wait()

            prompt.Enabled = true

        end

    end

end)

^ i still need help with this and havent figured anything out

^ bumping as i still need help

Can you explain a bit more about the duplication issue? Because it looks okay in the picture. Also your coding is beautiful.

Thanks! I’ll send a picture of what I mean – but the prompts in no way should be showing more than one per button. Both prompts are using the F key, so this is an issue. (sending picture of what I mean in a moment)

edit: Also, the duplication fixes when you fully walk away, I might be able to fix it with a check (which I already tried doing)

Is that a different problem than what you talked about?
“but the prompts in no way should be showing more than one per button. Both prompts are using the F key, so this is an issue.”

In the picture above, it shows 2 different prompts with F key, but in the picture below, it shows 2 of the same prompts on one part. Also, how often does this happen?

If I move around fast between two parts, that issue happens. This happened with my old system too.

Okay, so I’m going to assume that this is an issue with ProximityPromptService, and it’s prompt showing. Because there is no other event that would duplicate the prompts. So my main advice is first. Use a
if not ProximityPrompt:FindFirstChild("Whatever") then as a sanity check to make sure there isn’t a proximity prompt already there. Second, for the 1st picture given. You don’t seem to be filtering for same key prompts. Try doing a for loop to go through the table “t” to check if any of them are the same key. The problem with doing that though is that it’s likely the ones being shown that have the same key, are not the closest prompt. So you might have to intergrate an int value for distance between the prompt, and player.

local Distace = (Char.HumanoidRootPart.Position-ProximityPrompt.Position).Magnitude

Which you can then assign a sort of “layoutPriority” with the return like screen guis. Whichever has the lowest layoutPriority, you’ll show. It sounds a bit complicated, but it’s not too bad. You can update these values with a RunService RenderStepped event.

Unfortunately the distance check doesn’t work – I’m going to try scanning again

1 Like

So the scan function works – I ran it two times with a wait() in between and there haven’t been duplication issues so far, however, the prompts become invisible if I keep moving around in a fast manner (left right left right left right) at high speeds. If I move my camera in the smallest amount it fixes it, so I don’t think it’ll be too much of an issue. Thanks for the help ben!

1 Like

Mhm! Always here to help. : ) (Word limit)