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 3 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:

wait (1)

local on=false
local f=script.Parent.Parent.Frame

function click ()
    if on == false then
        on = true
        f:TweenPosition(UDim2.new(0.35,0,0.35,0),"Out","Bounce",1)
    else
        f:TweenPosition(UDim2.new(-0.35,0,0.35,0),"Out","Bounce",1) 
        if on == true then
            on = false
        end
    end
end

script.Parent.MouseButton1Click:Connect(click)

Please respond when you have the answer to this! I

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 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:

wait (1)

local on=false
local f=script.Parent.Parent.Frame

function click()
print("Detected click")
    if on == false then
        on = true
        f:TweenPosition(UDim2.new(0.35,0,0.35,0),"Out","Bounce",1)
    else
        f:TweenPosition(UDim2.new(-0.35,0,0.35,0),"Out","Bounce",1) 
        if on == true then
            on = false
        end
    end
end

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.

wait (1)

local on=false
local f=script.Parent.Parent.Frame

function click()
print("Detected click")
    if on == false then
        on = true
        f:TweenPosition(UDim2.new(0.35,0,0.35,0),"Out","Bounce",1)
    else
        f:TweenPosition(UDim2.new(-0.35,0,0.35,0),"Out","Bounce",1) 
        if on == true then
            on = false
        end
    end
end

script.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 — 3y
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 — 3y
0
Copy all my script and replace it with yours. DevMaster333 215 — 3y
0
That's what I did... and it's still not working. Contact me through my Discord: Apple King#4016 Jacobbron -8 — 3y
Ad

Answer this question