Whenever I destroy a Proximity Prompt it destroys it but the GUI for the Proximity Prompt still stays on the screen.
This was never the issue before but for some reason I suddenly started experiencing it in my game. Any help is appreciated!
Here is the Test file:
ProximityPrompt.rbxl (62.4 KB)
Here is the example of what I’m facing:
The script that handles the ProximityPrompt:
-- By: PERSONIFIEDPIZZA --
local UserInputService = game:GetService("UserInputService")
local ProximityPromptService = game:GetService("ProximityPromptService")
local TweenService = game:GetService("TweenService")
local TextService = game:GetService("TextService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")
local GamepadButtonImage = {
[Enum.KeyCode.ButtonX] = "rbxasset://textures/ui/Controls/xboxX.png",
[Enum.KeyCode.ButtonY] = "rbxasset://textures/ui/Controls/xboxY.png",
[Enum.KeyCode.ButtonA] = "rbxasset://textures/ui/Controls/xboxA.png",
[Enum.KeyCode.ButtonB] = "rbxasset://textures/ui/Controls/xboxB.png",
[Enum.KeyCode.DPadLeft] = "rbxasset://textures/ui/Controls/dpadLeft.png",
[Enum.KeyCode.DPadRight] = "rbxasset://textures/ui/Controls/dpadRight.png",
[Enum.KeyCode.DPadUp] = "rbxasset://textures/ui/Controls/dpadUp.png",
[Enum.KeyCode.DPadDown] = "rbxasset://textures/ui/Controls/dpadDown.png",
[Enum.KeyCode.ButtonSelect] = "rbxasset://textures/ui/Controls/xboxmenu.png",
[Enum.KeyCode.ButtonL1] = "rbxasset://textures/ui/Controls/xboxLS.png",
[Enum.KeyCode.ButtonR1] = "rbxasset://textures/ui/Controls/xboxRS.png",
}
local KeyboardButtonImage = {
[Enum.KeyCode.Backspace] = "rbxasset://textures/ui/Controls/backspace.png",
[Enum.KeyCode.Return] = "rbxasset://textures/ui/Controls/return.png",
[Enum.KeyCode.LeftShift] = "rbxasset://textures/ui/Controls/shift.png",
[Enum.KeyCode.RightShift] = "rbxasset://textures/ui/Controls/shift.png",
[Enum.KeyCode.Tab] = "rbxasset://textures/ui/Controls/tab.png",
}
local KeyboardButtonIconMapping = {
["'"] = "rbxasset://textures/ui/Controls/apostrophe.png",
[","] = "rbxasset://textures/ui/Controls/comma.png",
["`"] = "rbxasset://textures/ui/Controls/graveaccent.png",
["."] = "rbxasset://textures/ui/Controls/period.png",
[" "] = "rbxasset://textures/ui/Controls/spacebar.png",
}
local KeyCodeToTextMapping = {
[Enum.KeyCode.LeftControl] = "Ctrl",
[Enum.KeyCode.RightControl] = "Ctrl",
[Enum.KeyCode.LeftAlt] = "Alt",
[Enum.KeyCode.RightAlt] = "Alt",
[Enum.KeyCode.F1] = "F1",
[Enum.KeyCode.F2] = "F2",
[Enum.KeyCode.F3] = "F3",
[Enum.KeyCode.F4] = "F4",
[Enum.KeyCode.F5] = "F5",
[Enum.KeyCode.F6] = "F6",
[Enum.KeyCode.F7] = "F7",
[Enum.KeyCode.F8] = "F8",
[Enum.KeyCode.F9] = "F9",
[Enum.KeyCode.F10] = "F10",
[Enum.KeyCode.F11] = "F11",
[Enum.KeyCode.F12] = "F12",
}
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 promptTemplate = script:WaitForChild("Prompt")
local function createPrompt(prompt, inputType, gui)
local promptUI = promptTemplate:Clone()
local borderImage = promptUI:WaitForChild("Border")
local keyImage = promptUI:WaitForChild("KeyImage")
local keyText = promptUI:WaitForChild("KeyText")
local ObjectText = promptUI:WaitForChild("ObjectText")
local uiGradient = borderImage:WaitForChild("UIGradient")
local InfoFade = TweenInfo.new(0.3)
local function FadeProximity(num)
TweenService:Create(borderImage, InfoFade, {ImageTransparency = num}):Play()
TweenService:Create(keyImage, InfoFade, {ImageTransparency = num}):Play()
TweenService:Create(keyText, InfoFade, {TextTransparency = num}):Play()
TweenService:Create(ObjectText, InfoFade, {TextTransparency = num}):Play()
end
FadeProximity(0)
if inputType == Enum.ProximityPromptInputType.Gamepad then
if GamepadButtonImage[prompt.GamepadKeyCode] then
local icon = Instance.new("ImageLabel")
keyImage.Image = GamepadButtonImage[prompt.GamepadKeyCode]
end
elseif inputType == Enum.ProximityPromptInputType.Touch then
keyImage.Image = "rbxasset://textures/ui/Controls/TouchTapIcon.png"
else
local buttonTextString = UserInputService:GetStringForKeyCode(prompt.KeyboardKeyCode)
local buttonTextImage = KeyboardButtonImage[prompt.KeyboardKeyCode]
if buttonTextImage == nil then
buttonTextImage = KeyboardButtonIconMapping[buttonTextString]
end
if buttonTextImage == nil then
local keyCodeMappedText = KeyCodeToTextMapping[prompt.KeyboardKeyCode]
if keyCodeMappedText then
buttonTextString = keyCodeMappedText
end
end
if buttonTextImage then
keyImage.Image = buttonTextImage
elseif buttonTextString ~= nil and buttonTextString ~= '' then
keyText.Text = buttonTextString
else
error("ProximityPrompt '" .. prompt.Name .. "' has an unsupported keycode for rendering UI: " .. tostring(prompt.KeyboardKeyCode))
end
if ObjectText then
ObjectText.Text = prompt.ObjectText
else
return
end
end
if inputType == Enum.ProximityPromptInputType.Touch or prompt.ClickablePrompt then
local button = Instance.new("TextButton")
button.BackgroundTransparency = 1
button.TextTransparency = 1
button.Size = UDim2.fromScale(2, 2)
button.AnchorPoint = Vector2.new(0.5, 0.5)
button.Position = UDim2.fromScale(0.5, 0.5)
button.Parent = promptUI
local buttonDown = false
button.InputBegan:Connect(function(input)
if (input.UserInputType == Enum.UserInputType.Touch or input.UserInputType == Enum.UserInputType.MouseButton1) and
input.UserInputState ~= Enum.UserInputState.Change then
prompt:InputHoldBegin()
buttonDown = true
end
end)
button.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Touch or input.UserInputType == Enum.UserInputType.MouseButton1 then
if buttonDown then
buttonDown = false
prompt:InputHoldEnd()
end
end
end)
promptUI.Active = true
end
promptUI.Adornee = prompt.Parent
promptUI.Parent = gui
local connections = {}
local tweens = {}
local normalSize = borderImage.Size
local largerSize = UDim2.new(1.625, 0, 1.625, 0)
local triggeredTween = TweenService:Create(borderImage, TweenInfo.new(0.1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, true), {Size = largerSize})
table.insert(tweens, triggeredTween)
table.insert(connections, prompt.Triggered:Connect(function()
triggeredTween:Play()
triggeredTween.Completed:Connect(function()
borderImage.Size = normalSize
end)
end))
local progressTween
table.insert(connections, prompt.PromptButtonHoldBegan:Connect(function()
uiGradient.Enabled = true
uiGradient.Offset = Vector2.new(0, 0.4)
if progressTween then
progressTween:Cancel()
progressTween:Destroy()
end
progressTween = TweenService:Create(uiGradient, TweenInfo.new(prompt.HoldDuration, Enum.EasingStyle.Linear), {Offset = Vector2.new(0, -0.34)})
progressTween:Play()
progressTween.Completed:Connect(function()
end)
end))
table.insert(connections, prompt.PromptButtonHoldEnded:Connect(function()
if progressTween then
progressTween:Cancel()
progressTween:Destroy()
end
uiGradient.Enabled = false
end))
local function setColor()
local color = prompt:GetAttribute("Color")
if typeof(color) == "Color3" then
borderImage.ImageColor3 = color
keyImage.ImageColor3 = color
keyText.TextColor3 = color
keyText.TextStrokeColor3 = color
end
end
setColor()
table.insert(connections, prompt:GetAttributeChangedSignal("Color"):Connect(setColor))
local function cleanup()
table.insert(tweens, progressTween)
for _, connection in ipairs(connections) do
if connection then
connection:Disconnect()
end
end
for _, tween in ipairs(tweens) do
if tween then
tween:Cancel()
tween:Destroy()
end
end
FadeProximity(1)
task.wait(.5)
promptUI.Parent = nil
end
return cleanup
end
local function onLoad()
ProximityPromptService.PromptShown:Connect(function(prompt, inputType)
if prompt.Style == Enum.ProximityPromptStyle.Default then
return
end
if prompt:GetAttribute("Style") == "Glow" then
local gui = getScreenGui()
local cleanupFunction = createPrompt(prompt, inputType, gui)
prompt.PromptHidden:Connect(function()
cleanupFunction()
end)
end
end)
end
onLoad()