Ad
Log in to vote
0

How do I make the script change a MaxActivationDistance?

Asked by 7 years ago
Close = script.Parent
Open = script.Parent.Parent.OpenButton

function onClicked()
    Open.Transparency = 1
    Open.CanCollide = false
    Open.ClickDetetctor.MaxActivationDistance = 0
    Close.Transparency = 0
    Close.CanCollide = true
    Close.ClickDetector.MaxActivationDistance = 12
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

How do I make the script change the MaxActivationDistance of a ClickDetector?

0
Make sure you've opened up an 'Output' pane. Also, pay attention to the squiggly lines underneath any part of your code for potential errors. Redbullusa 1580 — 7y

3 answers

Log in to vote
0
Answered by 7 years ago

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:

Close = script.Parent
Open = script.Parent.Parent.OpenButton

function onClicked()
    Open.Transparency = 1
    Open.CanCollide = false
    Open.ClickDetector.MaxActivationDistance = 0
    Close.Transparency = 0
    Close.CanCollide = true
    Close.ClickDetector.MaxActivationDistance = 12
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

I hope this helps!

Ad
Log in to vote
0
Answered by
dyler3 1510 Moderation Voter
7 years ago

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.

Log in to vote
-1
Answered by 7 years ago
PLEASE give us what 'Open' and 'Close' would equal. Like 
'Open = TextButton'
'Close = Part'

Theres a couple problems ERRORS

1

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. ...

2

Your word ClickDetector Is typed incorrect.

3

Your 'Open' statment in your Function would error due to the ClickDetector is not valid in your Button.

Close = script.Parent  -- I am guessing this is a Part
Open = script.Parent.Parent.OpenButton -- Hoping this is a Part with it named OpenButton... (With a ClickDetector in it) :/

function onClicked()
    Close.Transparency = 1
    Close.CanCollide = false
    Open.ClickDetector.MaxActivationDistance = 0
    -- Add a wait(2) here due do it will open/close with like 0.0015th of a second.
    Close.Transparency = 0
    Close.CanCollide = true
    Open.ClickDetector.MaxActivationDistance = 12
end

Open.ClickDetector.MouseClick:connect(onClicked)

Answer this question