ProximityPrompt not working?

Hey there! So, i made a script (StarterPlayerScripts, local script) and it loops through the parts, when you either press the button/press E to trigger the proximity prompt, it fires a remote.

local v1 = game:GetService("ReplicatedStorage"):WaitForChild("Assets"):WaitForChild("Remotes"):WaitForChild("Buy") --named v1 cuz i was lazy xd
local player = game:GetService("Players").LocalPlayer

for _, v in pairs(game:GetService("Workspace"):WaitForChild("__MAP"):WaitForChild("ButtonParts"):GetDescendants()) do
	if v:FindFirstChild("Prompt") then --Prompt is attachment where i set the GuiPrompt's adornee. Also where the proximityPrompt is.
		local Button = v.GuiPrompt.Button
		local Prox = v.Prompt.ProximityPrompt
		v.GuiPrompt.Parent = player.PlayerGui





1 Like

I think the function ProximityPrompt.Triggered works only in server scripts and not local ones.
Try to make a normal script

1 Like

Tried that, didn’t work, thats why i switched to local script honestly, i thought it would fix it. The first proximityPrompt works not the second one tho

What settings do you use for the proximityprompt?

1 Like

Oh. Right, sorry.

What error are you getting in the console?

Without seeing your game’s architecture, it’s difficult to diagnose what your issue is.

As @officialReaperJR said, proximity prompts are fired by the client and received by the server, just like RemoteEvents (after all, they’re the client interacting with something on the server).

If you’re looking to loop through the parts in the workspace when a proximity prompt is fired, tried something like this:

-- It's good to steer clear of anonymous functions, but in testing this works fine
    -- Stored the path of your parts here for readability
    local buttonParts = game.Workspace:FindFirstChild("_MAP"):FindFirstChild("ButtonParts")
    -- Iterates through the children of buttonParts
    for k, v in pairs(buttonParts:GetDescendants() do
        -- Evaluates name and object-class of the currently iterated object
        -- Dissimilar to your code: you don't need to call :FindFirstChild() method when
        -- you're already going to be iterating through the object
        if v.Name == "Prompt" and v:IsA("Attachment") then
            -- your code here

Again, please provide more info so I can help more!

1 Like

So, to start off, its literally not detecting the trigger so its not the server nor the remote.

It prints “v” but it doesn’t print when i click “E”

I renamed everything so its a lot better now and not so hard to configure

Inside prompt is the ProximityPrompt just forgor to open :skull:


I see.

What you’re looking for is a server script to detect the proximity prompt, and a local script within StarterPlayerScripts to detect when the player presses E, with code not too dissimilar to this:

local PPS = game:GetService("ProximityPromptService")
local UIS = gameLGetService("UserInputService")

-- Fired when a prox. prompt becomes visible on a screen, fired client-side
    -- Fires whenever the client provides input
        -- Checks whether the input "inp" matches the E key
        if inp == Enum.KeyCode.E then
            -- your code here

May need a little tweaking as it’s untested.

1 Like

Oh i see, sorry for not pointing this out but im trying to only detect when the player presses “E” or clicks the button is when the player is near the part.

Which is why im using proximity prompt

Ah, I see.

You might have better luck using the following:

In ServerScriptService:

-- Fired on the proximity prompt completing
    -- Finds the magnitude of the base part of the player
    -- checks whether it's 10 studs from the part
    -- If it isn't, the if statement is never continued
    if player:FindFirstChild("HumanoidRootPart").Position.Magnitude <= 10 then
        -- your code here

In StarterPlayerScripts:

local PLYRS = game:GetService("Players")
local plyr = PLYRS.LocalPlayer
local character = plyr.Character or plyr.CharacterAdded:Wait()

local RS = game:GetService("ReplicatedStorage")
local RE = RS:FindFirstChild("RemoteEvent") or RS:WaitForChild("RemoteEvent")

-- Same as the script in ServerScriptService
    if inp == Enum.KeyCode.E and character.HumanoidRootPart.Position.Magnitude <= 10 then
        -- your code here
1 Like

Here is the same thing im doing

But here, the proximity prompt is already with a radius property and also ur calculating only the magnitude and not the player magnitude - gate magnitude (or other way around idrk)

In the first snippet of code, you’re calling a function whenever a proximity prompt fires (or, to put it plainly, whenever the circle around the proximity prompt completes).

You can definitely forego the second snippet of code in favour of changing the property that affects how far away a character has to be before the prox. prompt is displayed on the player’s screen (though having this second snippet of code is a backup, and objectively more precise in calculating the distance between the player’s character and the part).

Funnily enough, I made a mistake in the second snippet of code, should be more along the lines of:

if math.abs(part.Position.Magnitude - player:FindFirstChild("HumanoidRootPart").Position.Magnitude) <= 10 then

Either way, the more important part of my comment was the script in StarterPlayerScripts, which handles user input (though again, replace the character.HumanoidRootPart.Position.Magnitude with the snippet of code in this comment.

Hope this helps.

1 Like