Architecture for Dialogue System -- How to get all ProximityPrompts in Game?

I’ve been making a dialogue system for my game. I plan to make it so that every proximityprompt with a certain value “Dialogue” in it will trigger a RemoteEvent upon use.

Is there any way to make a serverscript that can listen to all these prompts to check when they’ve been triggered? Is it fine to just put a script for every individual prompt? That just feels unoptimized.

This is mainly an architecture question, so any other ways of implementing this could help a lot!

1 Like

can’t you do .PromptTriggered on the client? why handle dialogues on the server?

The CollectionService is an alternative to putting a script in many objects. Tag all of the ProximityPrompt objects with “Dialogue” and then this code will run ProcessPrompt for each object with that tag.

local CollectionService = game:GetService("CollectionService")
local function ProcessPrompt(part)
  -- Code which runs for each ProximityPrompt
end
for _,part in CollectionService:GetTagged("Dialogue") do
  ProcessPrompt(part)
end
CollectionService:GetInstanceAddedSignal("Dialog"):Connect(ProcessPrompt)
2 Likes

you can use ProximityPromptService to tell when a prompt is triggered.

E.g.

local PromptService = game:GetService('ProximityPromptService')

PromptService.PromptTriggered:Connect(function(Prompt, Player)
    print('Prompt Triggered [', Prompt, '] By Player:'..Player.Name)
end)

1 Like

…or if you want to go through the primitive way, loop through game and add the PromptTiggered event there

for i,prompt in workspace:GetChildren() do
if prompt:IsA("ProximityPrompt") then
prompt.PrompTriggered:Connect(function(...)
end)
end
end