I am trying to create a material changing part for my game. It is supposed to have a flicker effect by changing the material of the part between concreate and neon when the player clicks on the part.
Unfourunetly when I go in game my script does not seem to be working. Not even the click detector appears. It just stays concreate.
local Material = part.Material == Enum.Material
local detector = Instance.new("ClickDetector")
detector.Parent = part
local function updateVisuals()
if part.Material == Enum.Material.Concrete then
part.BrickColor = BrickColor.new("Yellow flip/flop")
part.Material = Enum.Material.Neon
else
part.BrickColor = BrickColor.new("Bright yellow")
part.Material = Enum.Material.Concrete
end
end
local function onToggle()
Material = not Material
updateVisuals()
end
updateVisuals()
detector.MouseClick:Connect(onToggle)
I have just tested it out, and it works perfectly.
Tho, why are you creating a ClickDetector instead of having one already inside the part?
--Variables
local part = script.Parent
local Material = part.Material == Enum.Material
local detector = part.ClickDetector
--Functions
local function updateVisuals()
if part.Material == Enum.Material.Concrete then
part.BrickColor = BrickColor.new("Yellow flip/flop")
part.Material = Enum.Material.Neon
else
part.BrickColor = BrickColor.new("Bright yellow")
part.Material = Enum.Material.Concrete
end
end
local function onToggle()
Material = not Material
updateVisuals()
end
--Logic
updateVisuals()
detector.MouseClick:Connect(onToggle)