So I am trying to get my GUI to have a animated open to it and instead of having a text button to open this with I am using ClickDetector and it's not really working, here's the script I'm using to do this:
01 | wait ( 1 ) |
02 |
03 | local on = false |
04 | local f = script.Parent.Parent.Frame |
05 |
06 | function click () |
07 | if on = = false then |
08 | on = true |
09 | f:TweenPosition(UDim 2. new( 0.35 , 0 , 0.35 , 0 ), "Out" , "Bounce" , 1 ) |
10 | else |
11 | f:TweenPosition(UDim 2. new(- 0.35 , 0 , 0.35 , 0 ), "Out" , "Bounce" , 1 ) |
12 | if on = = true then |
13 | on = false |
14 | end |
15 | end |
16 | end |
17 |
18 | script.Parent.MouseButton 1 Click:Connect(click) |
Please respond when you have the answer to this! I
You want to use MouseClick since MouseButon1Click is not a valid member of ClickDetector. I am not sure why you put a wait(1) at the start of your script but for the sake of keeping your script as it is, here's my fix:
01 | wait ( 1 ) |
02 |
03 | local on = false |
04 | local f = script.Parent.Parent.Frame |
05 |
06 | function click() |
07 | print ( "Detected click" ) |
08 | if on = = false then |
09 | on = true |
10 | f:TweenPosition(UDim 2. new( 0.35 , 0 , 0.35 , 0 ), "Out" , "Bounce" , 1 ) |
11 | else |
12 | f:TweenPosition(UDim 2. new(- 0.35 , 0 , 0.35 , 0 ), "Out" , "Bounce" , 1 ) |
13 | if on = = true then |
14 | on = false |
15 | end |
16 | end |
17 | end |
18 |
19 | script.Parent.MouseClick:Connect(click) |
You put the script under ClickDetector so that script.Parent = ClickDetector.
To confirm that the click() function runs you add a print inside it.
*Edit
For gui's you're supposed to use either a TextButton or an ImageButton. Once you add either one of those, you can use your initial line (script.Parent.MouseButton1Click:Connect(click)) in the local script under it. Here's an edit of your script for using a TextButton or MouseButton with GUIs.
01 | wait ( 1 ) |
02 |
03 | local on = false |
04 | local f = script.Parent.Parent.Frame |
05 |
06 | function click() |
07 | print ( "Detected click" ) |
08 | if on = = false then |
09 | on = true |
10 | f:TweenPosition(UDim 2. new( 0.35 , 0 , 0.35 , 0 ), "Out" , "Bounce" , 1 ) |
11 | else |
12 | f:TweenPosition(UDim 2. new(- 0.35 , 0 , 0.35 , 0 ), "Out" , "Bounce" , 1 ) |
13 | if on = = true then |
14 | on = false |
15 | end |
16 | end |
17 | end |
18 |
19 | script.Parent.MouseButton 1 Click:Connect(click) |
Here's how it should look like in your explorer: https://prnt.sc/vggbde (ScreenGui --> TextButton --> LocalScript)