Why is proximity prompt not working for some items but works for others?

Hi! I have an item service and item stats modules for a game I’m working on. It is a round-based game like Piggy. However, some items like keys proximity prompt appears while others don’t. All items are created the same and have primary parts and stuff. Please help.

-- Item Service
local itemService = {}
itemService.__index = itemService

local rs = game:GetService("ReplicatedStorage")
local itemFolder = rs:WaitForChild("Items")
local itemStats = require(rs:WaitForChild("Utilities"):WaitForChild("ItemStats"))

local itemsFolder = workspace:WaitForChild("Items")

-- Creates a Proximity Prompt for the item
local function newProximity(item)
	local itemName = item.Name
	local itemModel = item.Model
	local proximityPrompt = Instance.new("ProximityPrompt")
	proximityPrompt.ActionText = itemStats[itemName].ActionText
	proximityPrompt.ObjectText = itemStats[itemName].ObjectText
	proximityPrompt.HoldDuration = itemStats[itemName].HoldDuration
	proximityPrompt.KeyboardKeyCode = itemStats[itemName].Key
	proximityPrompt.MaxActivationDistance = itemStats[itemName].MaxActivationDistance
	-- When player has held it 
	if proximityPrompt.HoldDuration == 0 then
		proximityPrompt.Triggered:Connect(function(plr)
			itemStats[itemName].OnProximityEnd(item, plr)
		end)
	else
		proximityPrompt.PromptButtonHoldBegan:Connect(function(plr)
			itemStats[itemName].OnProximityBegin(item, plr)
		end)
		proximityPrompt.Triggered:Connect(function(plr)
			itemStats[itemName].OnProximityEnd(item, plr)
		end)
	end
	proximityPrompt.Parent = itemModel.PrimaryPart
	return proximityPrompt
end

-- Creates a new item and pales it on the map
function itemService.new(itemName, position, orientation)
	local item = setmetatable({}, itemService)
	item.Name = itemName
	item.Position = position
	item.Orientation = orientation
	item.Model = itemFolder[itemName]:Clone()
	item.Model:SetPrimaryPartCFrame(CFrame.new(position) * CFrame.Angles(math.rad(orientation.X), math.rad(orientation.Y), math.rad(orientation.Z)))
	local proximity = newProximity(item)
	item.ProximityPrompt = proximity
	item.Model.Parent = itemsFolder
	return item
end


return itemService

-- ItemStats
local itemStats = {}

itemStats["Door"] = {
	Key = Enum.KeyCode.E,
	ActionText = "Hold to Open",
	ObjectText = "Door",
	HoldDuration = 5,
	MaxActivationDistance = 15, -- Studs
	PossiblePositions = {
		["Map"] = {
			[1] = {Position = Vector3.new(-79.651, 5.2, -1.15), Orientation = Vector3.new(0,0,0), Required = true},
		}
	},
	OnProximityBegin = function(item, plr)
		return
	end,
	OnProximityEnd = function(item, plr)
		if plr.Backpack:FindFirstChild("Copper Key") then
			item.ProximityPrompt:Destroy()
			plr.Backpack:FindFirstChild("Copper Key"):Destroy()
			item.Model.PrimaryPart.Transparency = 1
			item.Model.PrimaryPart.CanCollide = false
		elseif plr.Character:FindFirstChild("Copper Key") then
			item.ProximityPrompt:Destroy()
			plr.Character:FindFirstChild("Copper Key"):Destroy()
			item.Model.PrimaryPart.Transparency = 1
			item.Model.PrimaryPart.CanCollide = false
		end
	end,
}

itemStats["Laptop"] = {
	Key = Enum.KeyCode.E,
	ActionText = "Hold to Hack",
	ObjectText = "Laptop",
	HoldDuration = 10,
	MaxActivationDistance = 10, -- Studs
	PossiblePositions = {
		["Map"] = {
			[1] = {Position = Vector3.new(-91.3, 5.075, 21.55), Orientation = Vector3.new(0, 180, 0), Required = true},
		}
	},
	OnProximityBegin = function(item, plr)
		return
	end,
	OnProximityEnd = function(item, plr)
		-- Temporary
		workspace.DoorOpenPart1.Color = Color3.fromRGB(0,255,0)
	end,
}

itemStats["Red Key Code"] = {
	Key = Enum.KeyCode.E,
	ActionText = "Hold to Collect",
	ObjectText = "Red Key Code",
	HoldDuration = 0.5,
	MaxActivationDistance = 10, -- Studs
	PossiblePositions = {
		["Map"] = {
			[1] = {Position = Vector3.new(-91, 3.75, 40.5), Orientation = Vector3.new(0, 90, 0), Required = true},
		}
	},
	OnProximityBegin = function(item, plr)
		return
	end,
	OnProximityEnd = function(item, plr)
		print("Proximity Started")
		-- Temporary
		local toolClone = game.ReplicatedStorage["Red Key Code"]:Clone()
		toolClone.Parent = plr.Backpack
		item.Model:Destroy()
		workspace.DoorOpenPart1.Color = Color3.fromRGB(255,0,0)
	end,
}
return itemStats
1 Like

The proximity prompt for Red Key Code and Laptop is not showing up whilst Door Proximity Prompt Shows

1 Like

Is RequireLineOfSight on or off?

1 Like

On, but I don’t know if that is the problem or not, I will send a video of the problem

1 Like

robloxapp-20210606-1956394.wmv (2.4 MB)