Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I be able to make my script work for when you touch a brick?

Asked by 4 years ago

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:

01wait (1)
02 
03local on=false
04local f=script.Parent.Parent.Frame
05 
06function click ()
07    if on == false then
08        on = true
09        f:TweenPosition(UDim2.new(0.35,0,0.35,0),"Out","Bounce",1)
10    else
11        f:TweenPosition(UDim2.new(-0.35,0,0.35,0),"Out","Bounce",1)
12        if on == true then
13            on = false
14        end
15    end
16end
17 
18script.Parent.MouseButton1Click:Connect(click)

Please respond when you have the answer to this! I

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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:

01wait (1)
02 
03local on=false
04local f=script.Parent.Parent.Frame
05 
06function click()
07print("Detected click")
08    if on == false then
09        on = true
10        f:TweenPosition(UDim2.new(0.35,0,0.35,0),"Out","Bounce",1)
11    else
12        f:TweenPosition(UDim2.new(-0.35,0,0.35,0),"Out","Bounce",1)
13        if on == true then
14            on = false
15        end
16    end
17end
18 
19script.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.

01wait (1)
02 
03local on=false
04local f=script.Parent.Parent.Frame
05 
06function click()
07print("Detected click")
08    if on == false then
09        on = true
10        f:TweenPosition(UDim2.new(0.35,0,0.35,0),"Out","Bounce",1)
11    else
12        f:TweenPosition(UDim2.new(-0.35,0,0.35,0),"Out","Bounce",1)
13        if on == true then
14            on = false
15        end
16    end
17end
18 
19script.Parent.MouseButton1Click:Connect(click)

Here's how it should look like in your explorer: https://prnt.sc/vggbde (ScreenGui --> TextButton --> LocalScript)

0
This sadly did not work, the output did not say "Detected click" either. Jacobbron -8 — 4y
0
Are you getting any errors? Because this is working fine for me. This is how it should be in your workspace: https://prnt.sc/vgg31p DevMaster333 215 — 4y
0
Copy all my script and replace it with yours. DevMaster333 215 — 4y
0
That's what I did... and it's still not working. Contact me through my Discord: Apple King#4016 Jacobbron -8 — 4y
Ad

Answer this question