Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My script isn't locating the Button to Tween?

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

✓ Accepted answer

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!

2 comments

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.

0

No problem! Glad to help.

This discussion is preserved as it was. New answers, comments, and votes are closed.