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)