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

How to make this so it cannot be clicked? [closed]

Asked by 9 years ago

I want to make it so that when the button or B1 is Red it cannot be clicked but when it is Lime Green it can be clicked.

local B1 = workspace.Deathrun.Button1
local walk = workspace.Deathrun.walk1
local walk2 = workspace.Deathrun.walk2
function onClick()
    B1.BrickColor = BrickColor.new('Really red')
    walk2.CanCollide = false
    walk.CanCollide = false
    walk.Transparency = 1
    walk2.Transparency = 1
    print 'off'
    wait(5)
    print 'on'
    walk.Transparency = 0
    walk2.Transparency = 0
    walk2.CanCollide = true
    walk.CanCollide = true
    wait(5)
    B1.BrickColor = BrickColor.new('Lime green')
end
B1.ClickDetector.MouseClick:connect(onClick)

Locked by alphawolvess, ISellCows, ChemicalHex, and User#5978

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

4 answers

Log in to vote
1
Answered by 9 years ago

local B1 = workspace.Deathrun.Button1 local walk = workspace.Deathrun.walk1 local walk2 = workspace.Deathrun.walk2 function onClick() if B1.BrickColor ~= BrickColor.new('Really red') then B1.BrickColor = BrickColor.new('Really red') walk2.CanCollide = false walk.CanCollide = false walk.Transparency = 1 walk2.Transparency = 1 print 'off' wait(5) print 'on' walk.Transparency = 0 walk2.Transparency = 0 walk2.CanCollide = true walk.CanCollide = true wait(5) B1.BrickColor = BrickColor.new('Lime green') end end B1.ClickDetector.MouseClick:connect(onClick)

All I did was make a check on the BrickColor in the beginning which will function like a Debounce. If it is not Really red, then continue the cod. But, if the brick is red, do nothing. This will still let the mouse show that the button is clickable, however clicking when it's red will not run any code. If you want the mouse to not show, you'd need to get rid of the ClickDetector or maybe insert a red part in the same position but just enough to cover the whole part so you cannot click it.

Ad
Log in to vote
0
Answered by 9 years ago

My suggestion is that you should have a duplicate of the ClickDetector somewhere in ServerStorage, and on the click, remove it when it turns red. Then copy the duplicate from the ServerStorage and set it's parent to the button when it turns green. Here's the solution:

local B1 = workspace.Deathrun.Button1
local walk = workspace.Deathrun.walk1
local walk2 = workspace.Deathrun.walk2
local detector = game.ServerStorage.ClickDetector

function onClick()
    B1.BrickColor = BrickColor.new('Really red')
    B1.ClickDetector:Destroy()
    walk2.CanCollide = false
    walk.CanCollide = false
    walk.Transparency = 1
    walk2.Transparency = 1
    print 'off'
    wait(5)
    print 'on'
    walk.Transparency = 0
    walk2.Transparency = 0
    walk2.CanCollide = true
    walk.CanCollide = true
    wait(5)
    B1.BrickColor = BrickColor.new('Lime green')
    local newdetector = detector:Clone()
    newdetector.Parent = B1
end

B1.ClickDetector.MouseClick:connect(onClick)

Hope it helps!

0
I was thinking of this but concidering this has to be a model for someone's place I could not use server storage for this. Thank you though! Conmmander 479 — 9y
0
If ServerStorage does not satisfy your needs, you can replace the path to... Let's say game.Lighting perhaps that would be a solution Director1406 5 — 9y
0
Possibly though as I said before I would need to tell the owner of the place I am making the model for that they would need to put something in lighting. Maybe creating a folder in the model in which click detector is located to be cloned may work? Conmmander 479 — 9y
Log in to vote
0
Answered by
Uroxus 350 Moderation Voter
9 years ago

You could do what Director1406 posted and just have a folder or another click detector in another location and just clone it. However, this is not necessary as you can create instances with scripts!

You can do this using

click= Instance.new("ClickDetector", _____)

The second parameter of Instance.new() will be the location you want it to go to. So to incorporate this into your script:

local B1 = workspace.Deathrun.Button1
local walk = workspace.Deathrun.walk1
local walk2 = workspace.Deathrun.walk2
local click = --- Link this to the ClickDetector inside the button!

function onClick()
    B1.BrickColor = BrickColor.new('Really red')
    walk2.CanCollide = false
    walk.CanCollide = false
    walk.Transparency = 1
    walk2.Transparency = 1
    click:destroy()
    print 'off'
    wait(5)
    print 'on'
    walk.Transparency = 0
    walk2.Transparency = 0
    walk2.CanCollide = true
    walk.CanCollide = true
    wait(5)
    B1.BrickColor = BrickColor.new('Lime green')
    detector = Instance.new("ClickDetector", script.Parent)
    detector.Name = "ClickDetector"
end
B1.ClickDetector.MouseClick:connect(onClick)


Theoretically this should work, however I am not currently able to test this.

If this answered your question please accept my answer with the button on the right -> If this does not work, please do tell me and if you would like an explanation to how this works please do ask.

0
This works and does not. It does correctly create a new Clickdetector in the Button but for some reason I am unable to reuse the script. I am able to click it but in the script output nothing happens and the button does not change to red. Conmmander 479 — 9y
Log in to vote
-1
Answered by 9 years ago
local B1 = workspace.Deathrun.Button1
local walk = workspace.Deathrun.walk1
local walk2 = workspace.Deathrun.walk2

local value = false

function onClick()

if B1.BrickColor == "Really red" and value == false then

value = true

 B1.BrickColor = BrickColor.new('Really red')

walk2.CanCollide = false
    walk.CanCollide = false
    walk.Transparency = 1
    walk2.Transparency = 1

print 'off'
    wait(5)
    print 'on'

walk.Transparency = 0
    walk2.Transparency = 0
    walk2.CanCollide = true
    walk.CanCollide = true

 wait(5)

elseif B1.BrickColor == "Lime green" and value == true then

    B1.BrickColor = BrickColor.new('Lime green')

value = false

    end
end

B1.ClickDetector.MouseClick:connect(onClick)


0
This however does not work either. The brick is going to start out as lime green btw and when clicked turn to red. Conmmander 479 — 9y