Metal Detector Script Not Working

Hello. I am trying to code a metal detector. So if a player has a certain tool in their backpack, then a display part will turn red and play a sound… The problem is the display won’t turn red even when the certain part is in my backpack…

The code is below…

local detector = script.Parent
local Display = workspace.ToolDetect.Model2.Display
local debounce = false

local tooldetected = false
local beep = script.Parent.Sound


detector.Touched:Connect(function(hit)
	if debounce == false then 
		debounce = true
		local char = hit.Parent
		local player = game.Players:GetPlayerFromCharacter(char)
		if player ~= nil then
			for i,v in pairs(player.Backpack:GetChildren()) do
				if v:IsA("Flash Light") or v:IsA("Other") then
					tooldetected = true
				end
			end
			if tooldetected == true then
				Display.BrickColor = BrickColor.new("Really red")
				beep:play()
				tooldetected = false
			else
				Display.BrickColor = BrickColor.new("Lime green")
				tooldetected = false
			end
			wait(1.5)
			Display.BrickColor = BrickColor.new("Really Black")
		end
		debounce = false
	end
end)

Here is a video also:

im sorry but
flashlight isnt a valid class!
what your dealing with is a TOOL
i recommend you search on the devhub itself for tool and :isa and classes.

so replace isa with :IsA(“Tool”) and v.Name == “Flash Light”
Also you want to check the players character for that tool because equipped tools go there.

Sorry, I’m new to programming… Thanks.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.