How to trigger proximityprompts in CollectionService?

The title explains. How do you trigger a proximityprompt in collectionservice? I couldn’t find anything on the forums regarding my issue, so how do I go about that?

1 Like

Where would the proximityprompt be located exactly?

It would be located under a part that is parented to a model. (Workspace > Model > Part > ProximityPrompt)

What do you mean by this exactly?

Like, I want to make a script where i’d use collectionservice to trigger a proximity prompt, I’m not that good at explaining, sorry. It’s similar to using collectionservice for kill blocks.

How do you want to trigger the proximity prompt? I have my proximity prompt handler in one localscript.

Something like this:

ProximityPrompt.Triggered:Connect(function()

end

In this case, I think you mean something like this:

local PPS = game:GetService("ProximityPromptService")
local CS = game:GetService("CollectionService")

PPS.PromptTriggered:Connect(function(Prompt,Player) -- fires whenever any proximity prompt is triggered
    if (CS:HasTag(Prompt.Parent,"SpecialPart") then -- checks for tag
        -- do stuff
    end
end)
2 Likes

Well I don’t really mean any, just certain proximity prompts. Sorry if I wasted your time.

You can use


or

in a serverscript and have custom actions in a modulescript somewhere.

1 Like

That’s no problem. I think you perhaps mean something like this instead?

local CS = game:GetService("CollectionService")
ProximityPrompt.Triggered:Connect(function(player)
    for _, taggedPart in pairs(CS:GetTagged("CoolTag")) do
        -- do stuff
    end
end)

Nice. So do I put the name of the tag in place of “CoolTag”?

Yes! I’m glad this is what you were looking for :slight_smile:

Another question, do I create a tag first, or this script creates it for me?

Neither, you make the tag by tagging a part with that tag. It can be quite confusing, but in a nutshell, a tag is created when you assign it to a part, via AddTag. I suggest you use this plugin to ease that making and assigning tags.

I already have the plugin. I’m gonna try out the script to see if it works.

1 Like

Alrighty. If you don’t encounter any further difficulties, then you can mark my reply above as the answer to your post :slight_smile:

Isn’t this kind of redundant?

You’re listening for the Triggered event to be fired and then iterating through every proximity prompt in-game. Pretty sure this is the opposite of what OP wanted.

It said “How to Trigger Proximity Prompts in Collection Service” so therefore even looping it makes it trigger

To my understanding, OP wants to affect multiple parts when a ProximityPrompt is triggered.

Not exactly sure which if my replies you were mentioning, if you could provide that then that would be most appreciated.