ProximityPrompts randomly deciding not to work

Hello! Recently, I have been working on my own game. However, I have noticed a recurring issue that happens whenever I try to interact with a ProximityPrompt.
The prompt simply does not work. Screenshot of the code used to create the prompt itself is below.

I have tried using other events (such as TriggerEnded) but it still hasn’t worked. Sometimes, the ProximityPrompt.Triggered event actually works, however this is only on rare occasions.

The Prompt’s RequiresLineOfSight is turned off, the prompt is not cloned (it is created using Instance.new), the prompt is enabled. I have no idea why it isn’t working, but if someone knows or has had a similar problem to me and has fixed it, please tell me the solution.

image

3 Likes

But you mean that it only appears some certain times? Or is it the Triggered?
If not, can you explain the main issue?

Sorry if it’s written in your doubt. I didn’t understand very well.

1 Like

It’s the Triggered event not working. Sometimes it has worked before, but these only occur sometimes.

1 Like

Can you show the Triggered event? The code inside of it

Thanks.

1 Like

1 Like

Sorry if my response was incorrect.

But does the Fire Client work tho?
Or is it absolutely nothing?..

1 Like

Put print statements to help you troubleshoot before the if checks.
For example before the first if put:
print("amount = ", amount)

Then before the next one:
print("item.stackable = ", item.stackable)

Before the next if else put:
print(player:FindFirstChild(“Inventory”) :FindFirstChild(itemName))

This will let you know how far the script is getting, and why the if checks aren’t working.

The FireClient doesn’t work because of the Prompt.Triggered issue, normally it is supposed to send a message that only the player who picked up the item can see that shows how much items you got and what item you picked up.

Also, sorry for the late response.

1 Like

Something I’m beginning to be unsure of is if it’s a specific problem with the item that is being dropped, as I can pick up another item but not specifically this one.


(as you can see in the chat, I could pick up the wood item but picking up the other item was refusing to work for me)
I will be investigating this further and hopefully fix this issue.

1 Like


As seen in this video (if it loads), it shows me mining an ore, being unable to pick up the ore, then mining another ore and being able to pick up the drop.

1 Like

Does it print any error?

And I’m sorry for late response, I couldn’t responde before

1 Like

Unfortunately not, there is no error when I activate the ProximityPrompt
Also that’s fine

1 Like

I think the error is that the event is being connected very fast. I would recommend putting a wait before, but since it’s a Server Sided script, I recommend you to put it between a spawn task.

task.spawn(function()
task.wait(3)
-- rest of the triggered function (put all of the  connection)
end)

Otherwise, it’s the statement that’s giving “silent errors”. If it doesn’t work, i recommend you after to put it between pcall functions

(you can also change the task.wait timer, 1 second at min)

1 Like

If this way doesn’t work either, try this code:

task.spawn(function()
task.wait(2)
prompt.Triggered:Connect(function(player)
	
	task.spawn(function()
		task.wait(1)
		
		-- rest

		
		if item.stackable == true then
			local inventory = player:FindFirstChild("Inventory")
			if inventory == nil then
				print("Didn't find inventory. Trying to access it")
				repeat task.wait(.01)
					inventory = player:FindFirstChild("Inventory")
					print("Finding inventory..")
				until inventory ~= nil
			end

			local item = inventory:FindFirstChild(itemName)

			if item == nil then
				print("Didn't find item")
				repeat task.wait(.01)
					item = inventory:FindFirstChild(itemName)
					print("Finding item..")
				until item~= nil
			end
		else
			local inventory = player:FindFirstChild("Inventory")
			if inventory == nil then
				print("Didn't find inventory. Trying to access it")
				repeat task.wait(.01)
					inventory = player:FindFirstChild("Inventory")
					print("Finding inventory..")
				until inventory ~= nil
			end

			task.spawn(function()
				for i = 1, amount do
					local itemClone = item.object:Clone()
					itemClone.Values.Amount.Value = 1
					itemClone.Parent = inventory
				end
			end)
		end
	end)
end)
end)

This is an example of what @Scottifly gave (i think, sorry if i’m wrong for the credits)

1 Like

Have you tested this method yet?

image
I believe I have fixed it, I just moved the code that created the prompt down. (to below where the image of the drop was being added)

I don’t know how this fixed it but I guess it did

Unfortunately, the problem seems to have resurfaced and the ‘solution’ was only temporary. The issue is still occurring and I have absolutely zero idea why. If I create a new part that has a ProximityPrompt and prints the player’s name with it, it works completely fine. Because of this, I think it has something to do with the code / the part itself, but I don’t know what…

Are you using a serverscript(not a local script) directly inside the prompt as a child?

The script is a ModuleScript. The prompt itself is created within a function inside the module script that is then used when an ore is broken. The function is called on the server-side.

Something I have noticed is that when the prompt becomes a bit too old (around 3 seconds from what I can see) it stops working but if it is triggered before then it works. No idea if this is just a coincidence or actually related to the issue.