Custom ProximityPrompt Not Showing Up | Possible errors

Hi, I have a custom ProximityPrompt local script (inside StarterPlayerScripts) and My billboard Gui will not show up within the max activation distance. I have no errors in the output apart from one that appears when I move outside the max activation distance (Line 246, attempt to call a nil value). The script was working before when it didn’t include the “KeyImage” assets (Possible error?).

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

local localPlayer = Players.LocalPlayer

local playerGui = localPlayer:WaitForChild("PlayerGui")
local customPrompt = ReplicatedStorage:WaitForChild("Prompt")

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 RedKeyColor = Color3.new(1, 0, 0)
local GreenKeyColor = Color3.new(0, 1, 0)
local BlueKeyColor = Color3.new(0, 0, 1)
local PurpleKeyColor = Color3.new(0.666667, 0, 1)
local YellowKeyColor = Color3.new(1, 1, 0)
local rarityColors = {RedKeyColor, GreenKeyColor, BlueKeyColor, PurpleKeyColor, YellowKeyColor}
local rarityName = {"RedKey", "GreenKey", "BlueKey", "PurpleKey", "YellowKey"}

local BlueKeyImage = 'http://www.roblox.com/asset/?id=12437011629'
local RedKeyImage = 'http://www.roblox.com/asset/?id=13035015776'
local GreenKeyImage = 'http://www.roblox.com/asset/?id=10736453903'
local PurpleKeyImage = 'http://www.roblox.com/asset/?id=129697930'
local YellowKeyImage = 'http://www.roblox.com/asset/?id=10736459504'
local ImageTable = {RedKeyImage, GreenKeyImage, BlueKeyImage, PurpleKeyImage, YellowKeyImage}

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 promptUI = customPrompt:Clone()
	local frame = promptUI:WaitForChild("Frame")
	local bottomFrame = frame:WaitForChild("Bottom")
	local rightFrame = frame:WaitForChild("RightSide")
	local toolImage = rightFrame:WaitForChild("ToolImage")
	local topFrame = frame:WaitForChild("TopBar")
	local divider = topFrame:WaitForChild("Divider")
	
	local actionText = topFrame:WaitForChild("ActionText")
	local buttonText = topFrame:WaitForChild("ButtonText")
	local ToolType = bottomFrame:WaitForChild("ToolType")
	local ToolNickName = bottomFrame:WaitForChild("ToolNickName")
	local ToolName = bottomFrame:WaitForChild("ToolName")
	local textTable = {actionText, buttonText, ToolType, ToolNickName, ToolName}
	local buttonImage = topFrame:WaitForChild("ButtonImage")

	local function setRarity(rarity)
		local color = rarityColors[rarity]
		local image = ImageTable[rarity]
		
		print("Setting image for rarity:", rarity)
		print("Image URL:", image)
		
		toolImage.Image = image
		bottomFrame.BackgroundColor3 = color
		divider.BackgroundColor3 = color
		ToolNickName.TextColor3 = color
		
	local function updateUIFromPrompt()
		actionText.Text = prompt.ActionText
		ToolName.Text = prompt:WaitForChild("ToolName").Value
		ToolNickName.Text = prompt:WaitForChild("ToolNickName").Value
		ToolType.Text = prompt:WaitForChild("ToolType").Value
		setRarity(prompt:WaitForChild("ToolRarity").Value)

		if inputType == Enum.ProximityPromptInputType.Gamepad then
			if GamepadButtonImage[prompt.GamepadKeyCode] then
				buttonImage.Image = GamepadButtonImage[prompt.GamepadKeyCode]
			end
		elseif inputType == Enum.ProximityPromptInputType.Touch then
			buttonImage.Image = "rbxasset://textures/ui/Controls/TouchTapIcon.png"
		else
			buttonImage.Image = "rbxasset://textures/ui/Controls/key_single.png"
			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
				buttonImage.Image = buttonTextImage
			elseif buttonTextString ~= nil and buttonTextString ~= '' then
				buttonText.Text = buttonTextString
			else
				error("ProximityPrompt '" .. prompt.Name .. "' has an unsupported keycode for rendering UI: " .. tostring(prompt.KeyboardKeyCode))
			end
		end

	end
	updateUIFromPrompt()

	local tweensForFadeOut = {}
	local tweensForFadeIn = {}
	local tweenInfoFast = TweenInfo.new(0.2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)

	for _, object in ipairs(textTable) do
		table.insert(tweensForFadeOut, TweenService:Create(object, tweenInfoFast, { TextTransparency = 1 }))
		table.insert(tweensForFadeIn, TweenService:Create(object, tweenInfoFast, { TextTransparency = 0 }))
	end

	table.insert(tweensForFadeOut, TweenService:Create(frame, tweenInfoFast, { Size = UDim2.fromScale(0, 1), BackgroundTransparency = 1, Visible = false }))
	table.insert(tweensForFadeIn, TweenService:Create(frame, tweenInfoFast, { Size = UDim2.fromScale(1, 1), BackgroundTransparency = 0.5, Visible = true }))

	if inputType == Enum.ProximityPromptInputType.Touch or prompt.ClickablePrompt then
		local button = Instance.new("TextButton")
		button.BackgroundTransparency = 1
		button.TextTransparency = 1
		button.Size = UDim2.fromScale(1, 1)
		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

	local triggeredConnection
	local triggerEndedConnection

	triggeredConnection = prompt.Triggered:Connect(function()
		for _, tween in ipairs(tweensForFadeOut) do
			tween:Play()
		end
	end)       

	triggerEndedConnection = prompt.TriggerEnded:Connect(function()
		for _, tween in ipairs(tweensForFadeIn) do
			tween:Play()
		end
	end)

	promptUI.Adornee = prompt.Parent
	promptUI.Parent = gui
	for _, tween in ipairs(tweensForFadeIn) do
		tween:Play()
	end

	local function cleanupFunction()
		triggeredConnection:Disconnect()
		triggerEndedConnection:Disconnect()

		for _, tween in ipairs(tweensForFadeOut) do
			tween:Play()
		end

		wait(0.2)

		promptUI.Parent = nil
	end

	return cleanupFunction
	end
end

ProximityPromptService.PromptShown:Connect(function(prompt, inputType)
	if prompt.Style == Enum.ProximityPromptStyle.Default then
		return
	end

	local gui = getScreenGui()

	local cleanupFunction = createPrompt(prompt, inputType, gui)

	prompt.PromptHidden:Wait()

	cleanupFunction()
end) 
1 Like

What keycode are you using for the ProximityPrompt?