Custom Proximity Prompt Issues

Hi! So I’m working on an SCP-style game and I need a custom proximity prompt for interacting with stuff around you. It works just fine up until it needs to delete the prompt when you walk away from it, for some reason walking away from it causes your game to crash / studio to crash

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

local RS = game:GetService("ReplicatedStorage")

local playerGUI = plr:WaitForChild("PlayerGui")
local customPrompt = RS:WaitForChild("Prompt")

local function getScreenGui()
	local screenGui = playerGUI:FindFirstChild("ProximityPrompts")
	if screenGui == nil then
		screenGui = Instance.new("ScreenGui")
		screenGui.Name = "ProximityPrompts"
		screenGui.ResetOnSpawn = false
		screenGui.Parent = playerGUI
	end
	return screenGui
end

local function createPrompt(prompt, inputType, gui)
	local UI = customPrompt:Clone()
	
	UI.Adornee = prompt.Parent
	UI.Parent = gui
	
	local function cleanup()
		prompt:Destroy()
	end
	
	return cleanup
end

PPS.PromptShown:Connect(function(prompt, inputType)
	if prompt.Style == Enum.ProximityPromptStyle.Default then
		return
	end
	-- Custom Prompt
	local GUI = getScreenGui()
	local cleanup = createPrompt(prompt, inputType, GUI)
	
	prompt.PromptHidden:Connect(cleanup)
	
	
end)

Any help is welcome!

Move to #help-and-feedback:scripting-support

This is because Proximity Prompts are a roblox feature, and you can use ProximityPromptService and the enumerated for your custom ones.

Hope this helps!