Custom ProximityPrompt Not Regenerating

Hello DevForum, I have returned with yet another issue, this time including customising ProximityPrompts. My custom ProximityPrompt currently works when you initially interact with it, however when I walk away from it and walk back up to it, it fails to regenerate to prompt. I have tried asking for help with the Roblox Studio Community Discord server however because it is a niche issue, I failed to get the correct help. Here is the code that I created:

--[[

	Title: CustomPrompts.lua
	Author: 7hDev
	Description: Customised proximity prompts.

]]

local Players = game:GetService("Players")
local PromptService = game:GetService("ProximityPromptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local Player = Players.LocalPlayer
local CustomPrompt = ReplicatedStorage:WaitForChild("Prompt")

local function CreatePrompt(Prompt, InputType, Gui)
	local PromptUI = CustomPrompt:Clone()
	PromptUI:WaitForChild("Frame").Header.ObjectText.Text = workspace.Example.ClothingName.Value
	
	PromptUI.Adornee = Prompt.Parent
	PromptUI.Parent = Gui
	print(PromptUI.Parent)
	
	local Info = TweenInfo.new(0.2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false)
	local Tweens = {
		FrameTween = TweenService:Create(PromptUI.Frame, Info, {ImageTransparency = 0.2});
		HeaderTween = TweenService:Create(PromptUI.Frame.Header.ObjectText, Info, {TextTransparency = 0});
		BuyTween = TweenService:Create(PromptUI.Frame.Buy.TextButton, Info, {TextTransparency = 0});
		BasketTween = TweenService:Create(PromptUI.Frame.Basket.TextButton, Info, {TextTransparency = 0});
		PreviewTween = TweenService:Create(PromptUI.Frame.Preview.TextButton, Info, {TextTransparency = 0});
	}
	Tweens["FrameTween"]:Play()
	task.wait(0.2)
	
	for i,v in pairs(Tweens) do
		if v ~= "HeaderTween" then
			v:Play()
		end
	end
end

local function GetScreenGui()
	if Player:WaitForChild("PlayerGui"):FindFirstChild("ProximityPrompts") == nil then
		local ScreenGui = Instance.new("ScreenGui", Player.PlayerGui)
		ScreenGui.Name = "ProximityPrompts"
		ScreenGui.ResetOnSpawn = false
		return ScreenGui
	end
end

PromptService.PromptShown:Connect(function(Prompt, InputType)
	if Prompt.Style == Enum.ProximityPromptStyle.Default then
		return
	end
	local Gui = GetScreenGui()
	CreatePrompt(Prompt, InputType, Gui)
	Prompt.PromptHidden:Wait()
	for i,v in pairs(Player.PlayerGui.ProximityPrompts:GetChildren()) do
		if v.Name == "Prompt" then
			v:Destroy()
		end
	end
end)
1 Like

Your function is only returning the ScreenGui when it doesn’t exist. When you call it a second time it’s not returning the gui.

local function GetScreenGui()
	local ScreenGui=Player:WaitForChild("PlayerGui"):FindFirstChild("ProximityPrompts")
	if ScreenGui == nil then
		ScreenGui = Instance.new("ScreenGui", Player.PlayerGui)
		ScreenGui.Name = "ProximityPrompts"
		ScreenGui.ResetOnSpawn = false
	end
	return ScreenGui
end
2 Likes

I am returning the ScreenGui, you just rewrote what I had already written, just in a slightly different order. It originally works but after you walk back to, that’s where the problem is.

1 Like

your return ScreenGui is inside the if statement so only returns if the gui has not been created.
If the gui is found then it doesn’t return anything. I wrote it differently to return the gui if it’s already created too.

1 Like

I originally had it like the the way you had it, but I was just being thrown Infinite Yield warnings but I will try it again. However now the effect has been inverted. It parents to nil when I interact with it the first time, then when I walk away and return, it works as expected.
Edit: Fixed, I just need to remove the local variable inside the if statement.

2 Likes