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)
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.
OOOOO I love this, custom proximity prompts are my favorite thing to make
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)