ProximityPrompt Problem When :Destroy()

Hello! This is my first time making a thread in the dev forum. And I’m hoping to find a solution to my problem

Basically my problem is, Ok so i make a script and in that script (server) it clones a proximity prompt from the server storage and parents it to an item, Now i made it so everytime that proximity prompt is triggered it will destroy the item and the proximity prompt. Script below.

(Server Script)

-- Remotes
local SpawnItemRemote = game.ReplicatedStorage.SpawnItemRemote

-- Bindables
local proximityPromptBindable = game.ServerStorage:WaitForChild("ProximityPromptFromItemTriggeredBindable")

-- Variables
local itemModelFolder = game.ServerStorage.ItemModels


-- Runtime
SpawnItemRemote.OnServerEvent:Connect(function(plr)
	local itemTable = itemModelFolder:GetChildren()
	local randomItem = itemTable[math.random(1, #itemTable)]

	local character = plr.Character
	local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
	
	local proximityPrompt = game.ServerStorage.ItemFrame:WaitForChild("ProximityPrompt"):Clone()


	local itemSpawnCoordinates = humanoidRootPart.CFrame.LookVector * 10
	local itemClone = randomItem:Clone()
	itemClone.Position = humanoidRootPart.Position + Vector3.new(0, 5, 0) + itemSpawnCoordinates
	itemClone.Anchored = false
	itemClone.Parent = game.Workspace

	proximityPrompt.Parent = itemClone

	proximityPrompt.Triggered:Connect(function(plr)
		proximityPrompt:Destroy()
		proximityPromptBindable:Fire(plr, itemClone)
	end)
	


end)

Here is the receiving end of the Bindable. (Server Script)

proximityPromptBindable.Event:Connect(function(plr, itemPickedUp)
	local profile = playerData[plr.UserId]
	local itemId = itemPickedUp:GetAttribute("ItemID")
	if profile then
		profile:AddItem(itemId, 1, itemFrame)
		itemPickedUp:Destroy()
	end
end)

Ok so yeah after trying it it works fine but there’s this very weird problem. As shown in the video below:

https://gyazo.com/62828ae0a78c314636a87aa66316b520

Solutions I tried:

Only destroying the item and not the proximity prompt
Parenting the proximity prompt somewhere else then destroying
adding task.wait(), debri service., task.delay()
disabling first then destroying
also tried doing instance.new on the proximity prompt instead of cloning

So far nothing worked and I’ve been stuck on this for a while and I would really appreciate it if someone helped! Thanks.

if you haven’t already tried, attempt to disable the prompt first maybe? and if it doesn’t work try to destroy the item alongside disabling it ^^

Unfortunately I already tried that and it didn’t work. Thanks though.

Disable ProximityPrompt. Change the transparency of the object to 1, task.wait(1) and then destroy the object.
Since this is done server-side, you need to take into account the communication time with the client.

2 Likes

Thank you very much, that’s a really clever workaround lol. It worked.

1 Like

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