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!

2 Likes
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)
	wait(5)
	prompt.PromptHidden:Connect(cleanup)
	
	
end)

Maybe this, I see nothing wrong, other then that the Removing of it happens right when it spawns.

Now it just delays the crash, let me try the script with the default Roblox prompt and see if it crashes.

Turns out it’s the script, for some reason everytime I walk up to it and walk away it crashes studio

I don’t know if you want it to be like this

it look like that the problem is from this

i changed it too

local function cleanup()
		gui:Destroy()
	end

tell me if i am on the wrong track

OOOOO I love this, custom proximity prompts are my favorite thing to make :slight_smile:

So at first glance of looking at your script you did do a bit of copy and paste off the default roblox system which is good for a start although other than just a few tips and tricks I gave you realistically I don’t see anything wrong with the initial script that should be crashing your studio.

local ProximityPromptService = game:GetService("ProximityPromptService")
local PlayersService = game:GetService("Players")
local Player = PlayersService.LocalPlayer
local RS = game:GetService("ReplicatedStorage")
local playerGUI = Player:WaitForChild("PlayerGui")
local customPrompt = RS:WaitForChild("Prompt")

local function getScreenGui() -- def
	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() -- Assuming the customPrompt is a BillboardGui
	local Signals = {}
	UI.Adornee = prompt.Parent
	UI.Parent = gui
	
	Signals["Triggered"] = prompt.Triggered:Connect(function() -- Wrap your functions like this cause in the cleanup function were going to disconnect it
		
	end)
	
	local function cleanup()
		for _, CurrentSignal in pairs(Signals) do
			CurrentSignal:Disconnect()
		end
		
		UI:Destroy() -- Destroy the UI thats removing the BillboardGui
	end

	return cleanup
end

ProximityPromptService.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)
2 Likes

I’ll try this when I get back into working on the game! Thanks

Hey, so I noticed for this, you can’t click the proximity prompt. Instead, you can only press E.

The game I’m working on was never meant for mobile, so if you want to click it or use mobile you would need to add user input functions.

Here’s the video i followed, just add on to my code: Custom ProximityPrompt Tutorial | Roblox Studio - YouTube