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.
01 | local B 1 = workspace.Deathrun.Button 1 |
02 | local walk = workspace.Deathrun.walk 1 |
03 | local walk 2 = workspace.Deathrun.walk 2 |
04 | function onClick() |
05 | B 1. BrickColor = BrickColor.new( 'Really red' ) |
06 | walk 2. CanCollide = false |
07 | walk.CanCollide = false |
08 | walk.Transparency = 1 |
09 | walk 2. Transparency = 1 |
10 | print 'off' |
11 | wait( 5 ) |
12 | print 'on' |
13 | walk.Transparency = 0 |
14 | walk 2. Transparency = 0 |
15 | walk 2. CanCollide = true |
16 | walk.CanCollide = true |
17 | wait( 5 ) |
18 | B 1. BrickColor = BrickColor.new( 'Lime green' ) |
19 | end |
20 | B 1. ClickDetector.MouseClick:connect(onClick) |
01 | local B 1 = workspace.Deathrun.Button 1 |
02 | local walk = workspace.Deathrun.walk 1 |
03 | local walk 2 = workspace.Deathrun.walk 2 |
04 | function onClick() |
05 | if B 1. BrickColor ~ = BrickColor.new( 'Really red' ) then |
06 | B 1. BrickColor = BrickColor.new( 'Really red' ) |
07 | walk 2. CanCollide = false |
08 | walk.CanCollide = false |
09 | walk.Transparency = 1 |
10 | walk 2. Transparency = 1 |
11 | print 'off' |
12 | wait( 5 ) |
13 | print 'on' |
14 | walk.Transparency = 0 |
15 | walk 2. Transparency = 0 |
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.
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:
01 | local B 1 = workspace.Deathrun.Button 1 |
02 | local walk = workspace.Deathrun.walk 1 |
03 | local walk 2 = workspace.Deathrun.walk 2 |
04 | local detector = game.ServerStorage.ClickDetector |
05 |
06 | function onClick() |
07 | B 1. BrickColor = BrickColor.new( 'Really red' ) |
08 | B 1. ClickDetector:Destroy() |
09 | walk 2. CanCollide = false |
10 | walk.CanCollide = false |
11 | walk.Transparency = 1 |
12 | walk 2. Transparency = 1 |
13 | print 'off' |
14 | wait( 5 ) |
15 | print 'on' |
Hope it helps!
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
1 | 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:
01 | local B 1 = workspace.Deathrun.Button 1 |
02 | local walk = workspace.Deathrun.walk 1 |
03 | local walk 2 = workspace.Deathrun.walk 2 |
04 | local click = --- Link this to the ClickDetector inside the button! |
05 |
06 | function onClick() |
07 | B 1. BrickColor = BrickColor.new( 'Really red' ) |
08 | walk 2. CanCollide = false |
09 | walk.CanCollide = false |
10 | walk.Transparency = 1 |
11 | walk 2. Transparency = 1 |
12 | click:destroy() |
13 | print 'off' |
14 | wait( 5 ) |
15 | print 'on' |
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.
01 | local B 1 = workspace.Deathrun.Button 1 |
02 | local walk = workspace.Deathrun.walk 1 |
03 | local walk 2 = workspace.Deathrun.walk 2 |
04 |
05 | local value = false |
06 |
07 | function onClick() |
08 |
09 | if B 1. BrickColor = = "Really red" and value = = false then |
10 |
11 | value = true |
12 |
13 | B 1. BrickColor = BrickColor.new( 'Really red' ) |
14 |
15 | walk 2. CanCollide = false |
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?