'Enum' is not changing material

Hello! I’m trying to make a metal detector. Somehow, the material won’t change. Can you help fix this?

Script in model:

local DB = false

local function triggerDebounce(bool)
	DB = bool
end

script.Parent.Sensor.Touched:Connect(function(hit)
	
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	
	if player then
		if DB == false then
			triggerDebounce(true)
			script.Parent.Red.Material = Enum.Material.Neon
			script.Parent.Green.Material = Enum.Material.Metal
			wait(1)
			triggerDebounce(false)
		end
	end
	
end)

script.Parent.Sensor.TouchEnded:Connect(function(hit)
	script.Parent.Red.Material = Enum.Material.Metal
	script.Parent.Green.Material = Enum.Material.Neon
end)

put a print in each of your touch and touchended most likely it is firing both over and over which makes it seem like its not changing. because its setting back to default on the touchended

I did that and it worked. Turns out the print message works outside of the if-statement. Thanks.

1 Like