How to trigger proximityprompts in CollectionService?

Except that’s not what that script is doing.

You could achieve what OP is asking for by using ProximityPromptService. This would cut out the need to use CollectionService. Specifically you would want to use the PromptTriggered event (it returns the prompt instance, and the player who fired the prompt.)

There’s also other events that can be used to detect when input is ended and when input to a prompt starts.

I actually did suggest using PromptTriggered, but OP said it was not what they wanted.

PromptTriggered is almost the same as Triggered I might use this as personal reference and if looping is bad then what other methods you can use then?

Well not affect multiple parts, I just want to get collectionservice to do stuff to the player without having to do SO many scripts of the same code e.g: Change a player’s currency when triggering a prompt.

1 Like

PromptTriggered is fired whenever any proximity prompt in the game is triggered, which could be useful for a multitude of things.

1 Like

You’re confusing ProximityPrompt.Triggered with ProximityPromptService.PromptTriggered.

Also, sorry to interrupt, but how can I declare the “ProximityPrompt” variable to the multiple prompts that I’m gonna tag?

You don’t need to use CollectionService for this. What you want is something along the lines of this:

local ProximityPromptService = game:GetService("ProximityPromptService")

ProximityPromptService.PromptTriggered:Connect(function(Prompt, Player)
 -- this event will get fired when ANY proximity prompt gets triggered, you only need 1 script
-- you could modify the players currency here by checking what kind of prompt it is
end)

Okay, but how can I check what kind of prompt? I’m also new to scripting, sorry.

OP has already said this is not what they are looking for.

no lmao he literally just explained what he’s trying to do. collectionservice isnt needed to modify stats of players

Well, I’m trying to make a script where it can modify a player’s stats without having to make so much scripts with the same name inside the prompts.

Then in this case, yes, do as @v7zr suggested and use PromptTriggered. You can use CollectionService to check if the Prompt is supposed to handle currency, such as tagging it with “CurrencyPrompt”.

DO NOTE YOU ONLY NEED ONE SCRIPT IN THE ENTIRE GAME FOR THIS. Ideally you could name the ProximityPrompt for the action it does, or create a StringValue object within the prompt and assign it a value of what it does.

local ProximityPromptService = game:GetService("ProximityPromptService")

ProximityPromptService.PromptTriggered:Connect(function(Prompt, Player)
  if not Prompt:FindFirstChild("Action") then return end -- looks for an object named "Action" within the prompt

  if Prompt.Action.Value == "Cash" then
    Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + 10
  end
end)

1 Like

Collection service is arguably more efficient/simple

What’s efficient about creating a tag for every player in game? lmfao

I’m gonna try it out tomorrow, feel free to continue the conversation.

Not for a player, just a part that has a prompt inside it.

Again, you don’t need to do that because Roblox already gives you an event to listen to input from all prompts in-game from one script.

Another thing, parts can be tagged before you actually run any code.