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)