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)
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.
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!
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.
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)
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?