Proximity Prompt not triggering

My proximity prompt when its triggered, DOESNT EVEN PRINT at all.

				NewBattery.Attachment.ProximityPrompt.Triggered:Connect(function(plr)
					print('found battery')
					NewBattery.ProximityPrompt.Enabled = false
					NewBattery.Transparency = 1
					NewBattery.Sound:Play()
					
					local flash = nil
					
					for _,tool in ipairs(plr.Backpack:GetChildren()) do
						if string.match(tool.Name, "flashlight") then
							flash = tool
						end
					end
					
					for _,tool in ipairs(plr.Character:GetChildren()) do
						if string.match(tool.Name, "flashlight") then
							flash = tool
						end
					end
					
					flash.Percentage.Value += 10
				end)

Whenever I trigger it, nothing absolutely happens. Does anyone know a solution to this? I’m losing my sanity

Okay, there is no reason why that print statement shouldn’t work so it must be to do with the proximity prompt itself. Are you sure you’re triggering the right one and that it correlates directly with this script?

Have you checked what the Output said? Are there errors related to your Script?

Yes i am using the right proximity prompt

Yes but its completely silent, no errors

I suppose you only posted part of your code, and the error might not be in where you suspect the issue exists. If so, would you mind sending more (or if possible, all) of the Script’s contents?

		if Folder then
			if math.random(1,4) == 1 or 2 then
				local NewBattery = game.ReplicatedStorage.Battery:Clone()
				local Attachment = NewBattery.Attachment
				local Proximity = Attachment.ProximityPrompt
				
				NewBattery:PivotTo(
					Folder:GetChildren()[math.random(
					1,#Folder:GetChildren()
					)].CFrame
				)
				NewBattery.Parent = model
				
				Proximity.Triggered:Connect(function(plr)
					print('found battery')
					NewBattery.ProximityPrompt.Enabled = false
					NewBattery.Transparency = 1
					NewBattery.Sound:Play()
					
					local flash = nil
					
					for _,tool in ipairs(plr.Backpack:GetChildren()) do
						if string.match(tool.Name, "flashlight") then
							flash = tool
						end
					end
					
					for _,tool in ipairs(plr.Character:GetChildren()) do
						if string.match(tool.Name, "flashlight") then
							flash = tool
						end
					end
					
					flash.Percentage.Value += 10
				end)
			end
		end

While I don’t see any problem with your code, there is a smaller issue:

if math.random(1,4) == 1 or 2 then

if statements don’t treat or and and statements as part of the same expression. Luau/vanilla Lua (and many, if not all languages) evaluates expressions like this:

if (math.random(1, 4) == 1) or (2 ~= nil or 2 ~= false) then

The problematic line should be re-written as:

local chance = math.random(1, 4)
if chance <= 2 then

or

if math.random(1, 4) <= 2 then

The only suggestion to find the main issue is to add a warn or print in between blocks of code.

An example:

local Thing = 2

print("part 1")
if Thing == 3 then
	return
end

print("part 2")
for num = 1, 12 do
	if Thing == num then
		return
	end
end

print("part 3 end")