Script doesn't work, but there are no errors

I’m trying to make a system where when the player triggers the proximity prompt, their tool will be destroyed.

Even through there are no errors in output, it doesn’t work. It doesn’t even print anything.

local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
--
local RSEvents = RS.Events.NeedItem
local ShowYouDontHaveEvent = RSEvents.ShowYouDontHave
local HideYouDontHaveEvent = RSEvents.HideYouDontHave
--
local Part = script.Parent
local Prompt = Part.ProximityPrompt
--
Prompt.Triggered:Connect(function(player)
	--
	local ValueFolder = player:WaitForChild("ValueFolder")
	local InventoryValue = ValueFolder.InventoryValue
	-- PLAYER'S CHARACTER/BACKPACK
	if player.Character and player.Backpack then
		for i,v in pairs(player.Character:GetChildren() and player.Backpack:GetChildren()) do
			if v:IsA("Tool") then
				--
				v:Destroy()
				print("Destroy Item")
				InventoryValue.Value = false
				--
			elseif not v:IsA("Tool") then
				--
				print("Player does NOT have Item")
				ShowYouDontHaveEvent:FireClient(player)
				wait(3)
				HideYouDontHaveEvent:FireClient(player)
				--
			end
		end
	end
end)

If you need more information just ask.
Any help is appreciated!

Are you sure the prompt is triggering?

player.Character:GetChildren() and player.Backpack:GetChildren()

This should error or only iterate through the backpack. In lua and/or will not combine tables, you will either have to iterate over both separately or combine the tables.

Could you try replacing the code with this and show us the output? When a problem like this occurs, I generally add print statements to every if statement to see if it runs or not.

local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
--
local RSEvents = RS.Events.NeedItem
local ShowYouDontHaveEvent = RSEvents.ShowYouDontHave
local HideYouDontHaveEvent = RSEvents.HideYouDontHave
--
local Part = script.Parent
local Prompt = Part.ProximityPrompt
--
Prompt.Triggered:Connect(function(player)
	print("Triggered")
	--
	local ValueFolder = player:WaitForChild("ValueFolder")
	local InventoryValue = ValueFolder.InventoryValue
	-- PLAYER'S CHARACTER/BACKPACK
	if player.Character and player.Backpack then
		print("Player and Player.Character")
		for i,v in pairs(player.Character:GetChildren() and player.Backpack:GetChildren()) do
			print(v.Name)
			if v:IsA("Tool") then
				--
				v:Destroy()
				print("Destroy Item")
				InventoryValue.Value = false
				--
			elseif not v:IsA("Tool") then
				--
				print("Player does NOT have Item")
				ShowYouDontHaveEvent:FireClient(player)
				wait(3)
				HideYouDontHaveEvent:FireClient(player)
				--
			end
		end
	end
end)

I think I see what you’re saying, but I can’t quite do it.

local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
--
local RSEvents = RS.Events.NeedItem
local ShowYouDontHaveEvent = RSEvents.ShowYouDontHave
local HideYouDontHaveEvent = RSEvents.HideYouDontHave
--
local Part = script.Parent
local Prompt = Part.ProximityPrompt
--
Prompt.Triggered:Connect(function(player)
	--
	local ValueFolder = player:WaitForChild("ValueFolder")
	local InventoryValue = ValueFolder.InventoryValue
	-- PLAYER'S CHARACTER
	
	if player.Character then
		for i,v in pairs(player.Character:GetChildren()) do
			if v:IsA("Tool") then
				--
				v:Destroy()
				print("Destroy Item")
				InventoryValue.Value = false
				--
			elseif not v:IsA("Tool") then
				--
				print("Player does NOT have Item")
				ShowYouDontHaveEvent:FireClient(player)
				wait(3)
				HideYouDontHaveEvent:FireClient(player)
				--
			end
		end
	-- PLAYER'S BACKPACK
		
	elseif player.Backpack then
		for i,v in pairs(player.Backpack:GetChildren()) do
			if v:IsA("Tool") then
				--
				v:Destroy()
				print("Destroy Item")
				InventoryValue.Value = false
				--
			elseif not v:IsA("Tool") then
				--
				print("Player does NOT have Item")
				ShowYouDontHaveEvent:FireClient(player)
				wait(3)
				HideYouDontHaveEvent:FireClient(player)
				--
			end
		end	
	else
		--
	end
end)

This is what I have right now, but the if player.Character then statement wont check if the player has a tool or not, and If the player has it in their backpack it wont check that either.

How do you think I should fix this?

I’ve tried putting lots of if statements, but there are no errors.

I didn’t say to add “if” statements, I just said add print()'s after the “if” statement’s to see if they print

Oh, I did it before so I thought you meant that lol. And I also did put prints all over the place, no errors. I’m confused.

Oh okay! Well if it didn’t error before, it wouldn’t be supposed to error anyways, did any of the print()'s not print?

you shouldn’t use elseif for the backpack, a new if will work better. The tool should be a child of the player if equipped, if not equipped it will be in their backpack.