Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

The Part's Material Won't change from Neon To Plastic?

So Basically, The GUI Works and everything, but when it stops, the part Remains NEONed and not Plastic, Why?

local Red = workspace.Model.Car.Body.Red
local Blue = workspace.Model.Car.Body.Blue
local lightsFlick = false

script.Parent.MouseButton1Click:Connect(function()
    if lightsFlick == false then
        lightsFlick = true
    while lightsFlick == true do
    wait(0.1)
    Red.Material = Enum.Material.Plastic
    Blue.Material = Enum.Material.Neon
    wait(0.1)
    Blue.Material = Enum.Material.Plastic
    Red.Material = Enum.Material.Neon
        end
    end
    
    
    if lightsFlick == true then
        lightsFlick = false
        print("False")
    Red.Material = Enum.Material.Plastic
    Blue.Material = Enum.Material.Plastic
    Red.Reflectance = 0
    Blue.Reflectance = 0
    end
end)

3 comments

0

output?

0

"False"

0

The while loop has a condition that means it will end when lightsflick is false, the second if-then statement is thus unnecessary, just remove Line 19 and Line 26

1 answer

local Red = workspace.Model.Car.Body.Red
local Blue = workspace.Model.Car.Body.Blue
local lightsFlick = false

script.Parent.MouseButton1Click:Connect(function()

    if lightsFlick == true then
        lightsFlick = false
        print("False")
    	Red.Material = Enum.Material.Plastic
    	Blue.Material = Enum.Material.Plastic
    	Red.Reflectance = 0
    	Blue.Reflectance = 0
    end

    if lightsFlick == false then
        lightsFlick = true
        while lightsFlick == true do
            wait(0.1)
    	    Red.Material = Enum.Material.Plastic
    	    Blue.Material = Enum.Material.Neon
    	    wait(0.1)
    	    Blue.Material = Enum.Material.Plastic
    	    Red.Material = Enum.Material.Neon
        end
    end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.