Proximity Prompt script activating other proximity prompts scripts

I have some scripts to add something into the players backpack when the proximity prompt is triggered. I also made it so you can only have the script give you the tool if you don’t already have the tool. maybe that would help with this problem but I don’t know.

When I trigger the proximity prompt, I get other tools from other proximity prompt scripts, which I don’t want. I need a way for the service to know I’m talking about the proximity prompt that the script is inside of, instead of any proximity prompt. Is that possible?

Heres the code:


local ProximityPromptService = game:GetService("ProximityPromptService")


local ToolName = (script.Parent.Parent.ToolName.Value)
local Storage = game:GetService("ServerStorage")
local ProximityPrompt = script.Parent

local function onPromptTriggered(promptObject, Player)
	if Player and Player.Character then
		local Backpack = Player:WaitForChild("Backpack")
		local Tool = Storage:FindFirstChild(ToolName)
		if Tool and not Backpack:FindFirstChild(ToolName) then
			local ToolClone = Tool:Clone()
			ToolClone.Parent = Backpack
		end
	end
end


ProximityPromptService.PromptTriggered:Connect(onPromptTriggered)

Thanks! Keep in mind I’m pretty new to scripting so if its a really easy fix, thats why.

When dealing with proximity prompts using the ProximityPromptService you are effectively handling every proximity prompt in one place on the server, but you should at least check the promptObject.Name and use conditionals to make sure the right code is running for that prompt.

In your script you are doing the same thing for every proximity prompt, is that what you want?

1 Like

Yeah I’m doing the same script for every proximity prompt currently, would it affect it if I have different scripts?
Yeah I saw the promptObject parameter, is that what I should use?

You need to need to handle each prompt.Triggered event individually, or you can name each prompt and check it’s name in the passed prompt argument in promptservice.

1 Like

Sorry I’m pretty new still. how would I do that?

It’s all good.
Depends on how you want to do it. You can stick with using ProximityPromptService, just check the name of the prompt being passed in.
i.e

local function onPromptTriggered(promptObject, Player)

Check the name of that promptObject.

1 Like