Proximity prompt not working after cloned

I have been working on a game where you open a door, then a random room spawns. kinda like a randomized rogue game (randomly generated droids)

when making the proximity prompt script, I thought I was going crazy because it would not work whatsoever.

However, upon closer inspection, its a roblox issue… But is there any ways around this?

heres my code:

local prompt = workspace.Part.ProximityPrompt
local main = workspace.Part

prompt.Triggered:Connect(function()
	prompt:Destroy()
	local clone = main:Clone()
	clone.Position = main.Position + Vector3.new(main.Size.X, 0, 0)
	clone.Parent = workspace
	
	prompt = clone.ProximityPrompt
	main = clone

end)

in the script you did

local prompt = workspace.Part.ProximityPrompt
local main = workspace.Part

its not a roblox issue its yours. You define the proximity prompt from workspace but if there are multiple proximity prompts it will only get the proximity prompt first in the list

if you want to get all the proximity prompts instead of just the first one you should loop through workspace

local main = nil


for i,v in pairs(workspace:GetChildren()) do 
if v:FindFirstChild("ProximityPrompt") then
prompt.Triggered:Connect(function()
	prompt:Destroy()
	local clone = main:Clone()
	clone.Position = main.Position + Vector3.new(main.Size.X, 0, 0)
	clone.Parent = workspace
	
	prompt = clone.ProximityPrompt
	main = clone

end)
end
end

You destroyed the prompt before cloning…

y’all are clowning on me for messing up my code, but first this was a test code. second, I had just removed something a bit ago, if you want an actual real code here it is:

local prompt = workspace.Part.ProximityPrompt
local main = workspace.Part

prompt.Triggered:Connect(function()
	prompt:Destroy()
	local clone = main:Clone()
	clone.Position = main.Position + Vector3.new(main.Size.X, 0, 0)
	clone.Parent = workspace
	
	prompt = Instance.new("ProximityPrompt")
	prompt.Parent = clone
	main = clone

end)

Its a roblox issue. I asked another way around the issue. NOT for you guys to troubleshoot my code.

Please read my response. It is because you define prompt as

workspace.Part.ProximityPrompt

if this script is inside of each proximity prompt use script.parent instead. workspace.Part.ProximityPrompt will get the first instance of part then its proximity prompt

If the script was inside the proximity prompt, it would throw an error/

its a test place. theres only one part and tis called “part”

It would not throw an error. I dont know why you think it would.

it would because I tried it once ??

If part is constantly being changed then it will only reference the first part before it was changed. If you deleted it then it would be nil and wotn wrok

You cant do

worskpace.part.proximityprompt

do

script.parent.proximityprompt

literally the part was never changed because its a testing place. the only change to the part is cloning it, then assigning the clone as “part”

This is not the issue. The real issue is that the prompt is being destroyed before cloning the whole part again.

You want to destroy the prompt only after clone the part

local prompt = workspace.Part.ProximityPrompt
local main = workspace.Part

prompt.Triggered:Connect(function()
	
	local clone = main:Clone()
	prompt:Destroy()
	clone.Position = main.Position + Vector3.new(main.Size.X, 0, 0)
	clone.Parent = workspace
	
	prompt = clone.ProximityPrompt
	main = clone

end)

I dont see a loop or anything they only included this part of the code

check the entire thread please :slight_smile: i said it wasnt this issue.

because its the only part of code. i’ve said what feels like hundreds of times saying this is a test place and these are the only lines of code.

obviously the issue isnt gonna be solved, so ill just use a click detector or smth

based on purely only the information you have given (not a lot of information)

I am going to assume these things

  1. This is the entire script
  2. This is a script in serverscriptservice
  3. A different script is adding new parts

Based on these assumptions because you provided no information otherwise, the reason this is happening is because you define

workspace.Part.ProximityPrompt

however when you delete workspace.Part it makes it so that variable is equal to nil, not the most current workspace.part

If you are destroying the prompt before cloning the entire part, the prompt will not be cloned with the part.
Try the code I have given above and see if it fixes the issue or not.

the prompt shows up, but it still doesnt work.

what about reference issues? if he deletes the part the variable is equal to nil