Proximity Prompt Help

Hello.

I need some help with proximity prompts. How do I make a proximity prompt run for only the player? I’ve tried to use a local script but that hasn’t worked.

Does anyone know how I can make this?

Anything will help, thanks.

If you wanted to do something on the client when a player uses a proximity prompt like a Gui popup, you could use a RemoteEvent and call FireClient.

-- This part is meant for a normal Script.

local prox = -- Path to your ProximityPrompt
local RemoteEvent = -- Path to a RemoteEvent

prox.Triggered:Connect(function(player))
  RemoteEvent:FireClient(player)
end)

-- This part is meant for LocalScripts.

local RemoteEvent = -- Path leading to the same RemoteEvent at the beginning

RemoteEvent.OnClientEvent:Connect(function()
   print("This function got run")
end)

If you only needed to do something specific to a player on the Server, you could reduce this script down to just:

local prox = -- the ProximityPrompt
prox.Triggered:Connect(function(player)

  -- Do something using the "player" variable.

end)
1 Like

I would suggest looking into CollectionService as this is a great way too use proximity prompts localy:

Source: CollectionService

A great plugin to use with collectionservice is: Tag Editor - Roblox

Example Of How the code is used:

local CollectionService = game:GetService("CollectionService")

local function LocalPromptFunction (prompt)
	prompt.Triggered:Connect(function(player: Player)
       -- This will run when the prompt was triggered 
-- also this code is in a local script it cam be placed in a Gui,PlayerScripts etc
	end)
end

CollectionService:GetInstanceAddedSignal("LocalPrompt"):Connect(LocalPromptFunction )


for i,v in pairs(CollectionService:GetTagged("LocalPrompt")) do
	coroutine.wrap(LocalPromptFunction )(v)
end
1 Like