ProximityPrompt visible only when Tool is eqquiped

Hi,
First, sorry for my English, it may be bad (this is not my main language).

I will explain by following this points:

  1. What do you want to achieve?
    I’m trying to make a proximity prompt appear ONLY when the player has a tool equipped and trying to activate some specifics model by using Prox prompt service

  2. What is the issue?
    I’ve tried to use the “PromptShown” 's event but when I aproach the model I want to interact, it disapear (In fact it appear and instant disappear) but nerver came back, even with a Tool eqquiped.

  3. What solutions have you tried so far?
    I’ve tried to write this code inside a localScript to make the cuttingTable usable only when tool equipped, also, I simply use the prompt’s Name to detect wich model I want to use (cuttingTable in this case):

local PPS = game:GetService("ProximityPromptService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer

PPS.PromptShown:Connect(function(prompt)
	if prompt.Name == "CuttingTable" then
		if player.Character:FindFirstChildWhichIsA("Tool") ~= nil then
			prompt.Enabled = true
		else
			prompt.Enabled = false
		end
	end
end)

Did someone have a solution or something that can help me ?

Thank you !

6 Likes

A interesting issue :thinking: It looks as though on the API Reference that the first parameter is the Prox’s Input Type, maybe you can try Region3 instead or something?

Thx for replying.
I don’t think it’s related to distance.
My issue is more for the “If Tool in hand then prompt.Enabled = true” and “else prompt.Enabled = false”

I think what you could do, is make a LocalScript inside the Tool that actually enables or disables the ProximityPrompt that way?

--I'm guessing this is gonna be inside a LocalScript, since you want the Prompt to enable/disable for certain clients
local Tool = script.Parent

Tool.Equipped:Connect(function()
    ProximityPrompt.Enabled = true
end)

Tool.Unequipped:Connect(function()
    ProximityPrompt.Enabled = false
end)

I could be wrong though, but I feel as though this could be what you need?

1 Like

Yes, I’ve think about something like it.
I’m trying with something like

player.Character.ChildAdded:Connect(function()
	local tool = player.Character:FindFirstChildWhichIsA("Tool")
	if tool ~= nil then
		--Enable prompt
	end
end)

I do have a question though, why are you checking if the Tool is valid to the Player’s Character? Shouldn’t it already be there if you use the Equipped Event?

Because I will use this to work with more than one tool.
for exemple, the CuttingTable can be used with potatoes, carrot, …
So the player can go to the table with his food and use the table to cut

And when a tool is equipped, it’s moved to the character folder

If it’s a folder, then uh I don’t think it’ll be enabled to work from the Character…? I could be wrong though, also you could just enable specific ProximityPrompts for each tool?

Sorry, my english may be bad and doesn’t reflect what I want to say X)

If I use a Tool.Equipped event, i will need to set an event for each tool I want to interact with (or maybe I’m wrong ?)
But, If a function is fired when something is added to the Character (not a folder, I’ve make a mistake when explain) I can check if this object added is (or not) a tool. Because when you equip a tool it move to Character. And I’ve only one block of code for all of that that

(Sorry if i’m not clear :sweat_smile:)

Ah you’re fine, well client-sided if you use the Tool.Equipped event I don’t think you need to set an Event for each Tool? But server-sided I believe yes you do

Now from what you said, yeah that can be possible I believe but I think you can do the Changed event for that instead? Someone correct me on that :thinking:

I don’t think you need to set an Event for each Tool?

How you define the Tool which fire the event if it’s not written before?

Ok, I’ve made this script

local PPS = game:GetService("ProximityPromptService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer

local function ToolEquipped(prompt)
	local tool = player.Character:FindFirstChildWhichIsA("Tool")
	if tool ~= nil then
		prompt.Enabled = true
	end
end

local function CheckPrompt(prompt)
	if prompt.Name == "CuttingTable" then
		if player.Character:FindFirstChildWhichIsA("Tool") ~= nil then
			prompt.Enabled = true
		else
			prompt.Enabled = false
			player.Character.ChildAdded:Connect(function()
				ToolEquipped(prompt)
			end)
		end
	end
end

PPS.PromptShown:Connect(CheckPrompt)

It can be more compact but seems to work good.
The only issue that still here is the blink it make when we approach the prompt when no tool equipped.

3 Likes

I know this topic was 3 years ago, but could you specify where you put the finished script? And also what type of script it is e.g local script/normal script (server script)

1 Like