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

How to make a button turn object on and off?

Asked by 5 years ago

I've made a tv (started scripting like yesterday so im just kinda randomly doing stuff) but now I am attempting to have it turn back off when I hit the power button again. I want to get the decals to stop and the Brick color to turn back to green when the power button is pushed again. This is the script:

local ClickDetector = script.Parent.ClickDetector
local Brick = script.Parent
local OnOff = 1

function onMouseClick()
    Brick.Color = Color3.fromRGB(255,0,0) 
    while OnOff==1 do
        script.Parent.Parent.Screen.Decal.Texture = "rbxassetid://69103739"
        wait(0.5)
        script.Parent.Parent.Screen.Decal.Texture = "rbxassetid://19851297"
        wait(0.5)
        script.Parent.Parent.Screen.Decal.Texture = "rbxassetid://1204430503"
        wait(0.5)
        script.Parent.Parent.Screen.Decal.Texture = "rbxassetid://1262446339"
        wait(0.5)
    end
end

ClickDetector.MouseClick:connect(onMouseClick)

1 answer

Log in to vote
0
Answered by
TopBagon 109
5 years ago

hey, I think this should work fine

local ClickDetector = script.Parent.ClickDetector
local Brick = script.Parent
local OnOff = 1
local db = true

function onMouseClick()
    if db == true then
    db = false
    OnOff = 1
    Brick.Color = Color3.fromRGB(255,0,0) 
    while OnOff == 1 do
        script.Parent.Parent.Screen.Decal.Texture = "rbxassetid://69103739"
        wait(0.5)
        script.Parent.Parent.Screen.Decal.Texture = "rbxassetid://19851297"
        wait(0.5)
        script.Parent.Parent.Screen.Decal.Texture = "rbxassetid://1204430503"
        wait(0.5)
        script.Parent.Parent.Screen.Decal.Texture = "rbxassetid://1262446339"
        wait(0.5)
        end
    elseif db == false then
        OnOff = 0
        db = true
        Brick.Color = Color3.fromRGB(0,255,0)
    end
end

ClickDetector.MouseClick:connect(onMouseClick)

IDK about decals tho...

Ad

Answer this question