Roblox crash when attempt destroy ProximityPrompt

Hi, I am making a Inventory System and when i try to destroy a ProximityPromp Roblox Studio Crash with no error message

this is the full code, to repliclated u need create a part with one Attribute called itemType and just move closer and later move away until the box disappears

-- Servicios --
local Players = game:GetService("Players")
local Debris = game:GetService("Debris")
local RS = game:GetService("ReplicatedStorage")

-- Variables --
local plr = Players.LocalPlayer
local chr = plr.Character or plr.CharacterAdded:Wait()
local camera = workspace.CurrentCamera

local eventsFolder = RS:WaitForChild("Events")


-- Funciones --
function FilterItem(i)																						--Comprueba si es un Objeto
	local itemType = i:GetAttribute("itemType")
	
	if itemType and not i:FindFirstChildOfClass("ProximityPrompt") then
		local Promp = Instance.new("ProximityPrompt", i)
		
		Promp.MaxActivationDistance = 8
		Promp.ActionText =  "Get"
		Promp.ObjectText = i.Name
		Promp.UIOffset = Vector2.new(0, 80)
		
		Promp.PromptHidden:Connect(function()
			Promp:Destroy()
		end)
	end
end

function GetItem()
	
end

while task.wait(0.25) do
	local RP = chr:FindFirstChild("HumanoidRootPart")
	
	if RP then
		local region = Region3.new(RP.Position - 9 * Vector3.one, RP.Position + 9 * Vector3.one)
		local items = workspace:FindPartsInRegion3WithIgnoreList(region,{chr,camera})
		
		for _, i in items do
			FilterItem(i)
		end
	end
	
end

I don’t know if this error is mine or it is a Studio error

Thanks for making my Studio Crash!! No seriously I think this is a Studio bug that you should report. One workaround for your code is to make a function above this code that takes the prompt, do a task wait of a second, and then destroy it. That seemed to work.

Sure, I would like to do it but I don’t know how to report engine errors

and about waiting a few seconds, it works but I need it to be deleted instantly so it doesn’t work for me :frowning:

Hi just checking instead of destroying it can you just disable it?
Promp.enabled = false

1 Like

Maybe set delay to something lower like 0.05.

1 Like

Maybe just set its Parent to nil instantly and then destroy it in a second. Haven’t tried it but that might also work.

1 Like

If someone has the same problem, the solution is the following

		Promp.PromptHidden:Connect(function()
			Promp.Enabled = false
			task.wait()
			Promp:Destroy()
		end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.