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.

01local B1 = workspace.Deathrun.Button1
02local walk = workspace.Deathrun.walk1
03local walk2 = workspace.Deathrun.walk2
04function onClick()
05    B1.BrickColor = BrickColor.new('Really red')
06    walk2.CanCollide = false
07    walk.CanCollide = false
08    walk.Transparency = 1
09    walk2.Transparency = 1
10    print 'off'
11    wait(5)
12    print 'on'
13    walk.Transparency = 0
14    walk2.Transparency = 0
15    walk2.CanCollide = true
16    walk.CanCollide = true
17    wait(5)
18    B1.BrickColor = BrickColor.new('Lime green')
19end
20B1.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
01local B1 = workspace.Deathrun.Button1
02local walk = workspace.Deathrun.walk1
03local walk2 = workspace.Deathrun.walk2
04function onClick()
05    if B1.BrickColor ~= BrickColor.new('Really red') then
06        B1.BrickColor = BrickColor.new('Really red')
07        walk2.CanCollide = false
08        walk.CanCollide = false
09        walk.Transparency = 1
10        walk2.Transparency = 1
11        print 'off'
12        wait(5)
13        print 'on'
14        walk.Transparency = 0
15        walk2.Transparency = 0
View all 22 lines...

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:

01local B1 = workspace.Deathrun.Button1
02local walk = workspace.Deathrun.walk1
03local walk2 = workspace.Deathrun.walk2
04local detector = game.ServerStorage.ClickDetector
05 
06function onClick()
07    B1.BrickColor = BrickColor.new('Really red')
08    B1.ClickDetector:Destroy()
09    walk2.CanCollide = false
10    walk.CanCollide = false
11    walk.Transparency = 1
12    walk2.Transparency = 1
13    print 'off'
14    wait(5)
15    print 'on'
View all 26 lines...

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

1click= 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:

01local B1 = workspace.Deathrun.Button1
02local walk = workspace.Deathrun.walk1
03local walk2 = workspace.Deathrun.walk2
04local click = --- Link this to the ClickDetector inside the button!
05 
06function onClick()
07    B1.BrickColor = BrickColor.new('Really red')
08    walk2.CanCollide = false
09    walk.CanCollide = false
10    walk.Transparency = 1
11    walk2.Transparency = 1
12    click:destroy()
13    print 'off'
14    wait(5)
15    print 'on'
View all 25 lines...

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
01local B1 = workspace.Deathrun.Button1
02local walk = workspace.Deathrun.walk1
03local walk2 = workspace.Deathrun.walk2
04 
05local value = false
06 
07function onClick()
08 
09if B1.BrickColor == "Really red" and value == false then
10 
11value = true
12 
13 B1.BrickColor = BrickColor.new('Really red')
14 
15walk2.CanCollide = false
View all 40 lines...
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