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

My script isn't locating the Button to Tween?

Asked by 5 years ago

I made a local script that is placed directly into the Button and it adds a cool hover effect. I decided I want to have a local script under the ScreenGui that not only allows the Button to hover but any other button I add to the MainGui to have the same kind of effect without having to make another script.

I checked and couldn't find any reason the script is locating the Button as it should, but maybe that isn't the issue.

wait()

local OpenButton = script.Parent.NavButton.Open:WaitForChild("Button")

OpenButton.MouseEnter:connect(function()
    print("Mouse Entered")

    OpenButton:TweenPosition(UDim2.new(3.289, 0, 1.919, 0), "Out", "Quad", 0.2, true)
end)

OpenButton.MouseLeave:connect(function()
    print("Mouse Leave")

    OpenButton.TweenPosition(UDim2.new(3.289, 0, 2.019, 0), "Out", "Quad", 0.2, true)
end)

If you guys find the problem please let me know and I'll try and fix it!

1 answer

Log in to vote
1
Answered by
B_rnz 171
5 years ago
Edited 5 years ago

I think the error here is because you're calling mouse leave, but you cant run mouse leave if it hasnt entered:

So you would do something like:

Button.MouseEnter:Connect(function()
    -- Do something here
    Button.MouseLeave:Connect(function()
        -- Do something when it leaves.
    end)
end)

So your code should look like:

wait()

local OpenButton = script.Parent.NavButton.Open:WaitForChild("Button")

OpenButton.MouseEnter:connect(function()
    print("Mouse Entered")
    OpenButton:TweenPosition(UDim2.new(3.289, 0, 1.919, 0), "Out", "Quad", 0.2, true)

    OpenButton.MouseLeave:connect(function()
        print("Mouse Leave")
        OpenButton.TweenPosition(UDim2.new(3.289, 0, 2.019, 0), "Out", "Quad", 0.2, true)
    end)
end)

Hope this works!

0
Thank you B_rnz, I figured it wasn't the locating the button that was the problem. I corrected the issue and now it works great! Thank you. tawk1215 47 — 5y
0
No problem! Glad to help. B_rnz 171 — 5y
Ad

Answer this question