Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Using a screen gui to make a brick change material and colour then onclick change back?

Asked by 6 years ago

Hi, I am new to scripting and usually get help from the wiki but I could not find anything for this topic. Basically, I am trying to create a screen gui that when you press the button once the brick changes it's colour from Medium stone grey to Pastel yellow and the material also changes to neon. Then I want it when I press it again it changes back. I am terrible at scripting and I could not find much on the web, please help me. I had done multiple scripts before but deleted them, this was the one I was working on now:

lit = game.Workspace.IFE_1.yela
thevariable = 5


if thevariable<bob then
    script.Parent.MouseButton1Click:connect(function()
        lit.BrickColor = BrickColor.new("Pastel yellow")
        lit.Material = "Neon" 
         bob = 6
         wait(3)
         bob = 1
end)                                                                     --I thought what was happening was that it ran 
                                                                            -- the code back straight after but I added a wait 
                                                                           --  and nothing happened.
    if thevariable>1 then   
        lit.BrickColor = BrickColor.new("Medium stone grey")
        lit.Material = "Plastic"
    end
    end

Another code: _____________________________

local lit = game.Workspace.IFE_1.yela
local on = true

function on()
    on = true
    lit.BrickColor = BrickColor.new("Pastel yellow")
    lit.Material = "Neon"
    print(lit.BrickColor) 
    print(lit.Material)
end 

function off()
    on = false
    lit.BrickColor = BrickColor.new("Pastel yellow")
    lit.Material = "Neon"
    print(lit.BrickColor) 
    print(lit.Material)
end 

function onClick()
    if on == true then on() elseif on == false then off() end
end

excuse my noobiness :) thanks in advance.

1 answer

Log in to vote
0
Answered by 6 years ago

You can only use clicking functions and mouse filters on Button type of objects if you're making GUIs

debounce = false
Button.MouseButton1Click:connect(function()
    --Locate part
    if debounce == false then 
        part.Material = "New material"
        part.BrickColor = BrickColor.new("New color")
        debounce = true
    else
        part.Material = "Old material"
        part.BrickColor = BrickColor.new("Old color")
        debounce = false
    end
end)
0
I've spent 1 hour on this question lol i tried to avoid using else because i don't find it adjustable. Well done Ernie252 -4 — 6y
0
Ohhh....well I will remember this for the future then, thank you so much, I was spending hours on this! 5SaxWax5 2 — 6y
Ad

Answer this question