01 | Close = script.Parent |
02 | Open = script.Parent.Parent.OpenButton |
03 |
04 | function onClicked() |
05 | Open.Transparency = 1 |
06 | Open.CanCollide = false |
07 | Open.ClickDetetctor.MaxActivationDistance = 0 |
08 | Close.Transparency = 0 |
09 | Close.CanCollide = true |
10 | Close.ClickDetector.MaxActivationDistance = 12 |
11 | end |
12 |
13 | script.Parent.ClickDetector.MouseClick:connect(onClicked) |
How do I make the script change the MaxActivationDistance of a ClickDetector?
The code looks mostly good, but there is one small error.
Line 9: Open.ClickDetetctor.MaxActivationDistance = 0
If you look closely, you will see that ClickDetector is spelled incorrectly. Other than that, the code looks fine. Just be careful that you spell everything correctly when coding. Here is the fixed code:
01 | Close = script.Parent |
02 | Open = script.Parent.Parent.OpenButton |
03 |
04 | function onClicked() |
05 | Open.Transparency = 1 |
06 | Open.CanCollide = false |
07 | Open.ClickDetector.MaxActivationDistance = 0 |
08 | Close.Transparency = 0 |
09 | Close.CanCollide = true |
10 | Close.ClickDetector.MaxActivationDistance = 12 |
11 | end |
12 |
13 | script.Parent.ClickDetector.MouseClick:connect(onClicked) |
I hope this helps!
Nothing looks wrong with this script. Just make sure that the paths are all led to the correct object. I'm not sure what else would be the problem.
1 | PLEASE give us what 'Open' and 'Close' would equal. Like |
2 | 'Open = TextButton' |
3 | 'Close = Part' |
Theres a couple problems
ERRORS
if 'Close' = 'Model' then line 08 is a error due to you cant see a model. I would say 'Close' = 'Part' from the script but anyways. ...
Your word ClickDetector Is typed incorrect.
01 | Close = script.Parent -- I am guessing this is a Part |
02 | Open = script.Parent.Parent.OpenButton -- Hoping this is a Part with it named OpenButton... (With a ClickDetector in it) :/ |
03 |
04 | function onClicked() |
05 | Close.Transparency = 1 |
06 | Close.CanCollide = false |
07 | Open.ClickDetector.MaxActivationDistance = 0 |
08 | -- Add a wait(2) here due do it will open/close with like 0.0015th of a second. |
09 | Close.Transparency = 0 |
10 | Close.CanCollide = true |
11 | Open.ClickDetector.MaxActivationDistance = 12 |
12 | end |
13 |
14 | Open.ClickDetector.MouseClick:connect(onClicked) |