Cant do :connect() for GUI buttons when using object values

This is really giving me a headache,
what I’m trying to do is, whenever I hover over any button it will play a cool animation
for example, it enlarges, kind of like this:

Im going to have alot of buttons, and I might add more in the future. So for maximum optimization I wanted to make it so that I won’t need to configure my script and manually wire them to work for each button I add.

I decided to make a folder of objectValues, and assign a button for each one. then a script is going to loop through each one and make a :Connect() function.
image


^uses MouseButton1Down instead

It has a similar principle to this, Everytime a player is added, it automatically wires it so that it can detect if that player’s character was added or removed.
image

Everything looks right, I don’t get any errors, but it just doesn’t work. Whenever I click the button it doesnt print “click”
It is correctly looping through all the values!, but it just doesn’t do :connect() function.

I try to do this with parts, the same principle except its when u touch it
image
image
^And for some odd reason this works

I dont get it.
Next I try to go through the buttons inside the screengui instead
image
^AND THiS wOrks???

its literally the same thing! Why cant I use object values for gui buttons?

I open-sourced the place to test for yourself:

Am I doing something wrong or is studio broken?

Also is my method a good way for optimization GUIs?
Any help would be appreciated THANKS!
image

1 Like

For your first problem you can use MouseEnter and MouseLeave to connect when a mouse enters and leaves a button. For your next problem you can’t connect a TextButton with a object value for some reason.

Because, every client has their own gui objects, creating a normal object value and assign it in studio will only make its value FROM THE STARTERGUI, NOT PLAYERGUI.

You seem to be worried a lot about optimisation, so here are a few tips you should know.


1. Declare variables and functions as local
Local variables are faster than globals (the difference is actually miniscule, but its good practice to use locals)

Since globals in Luau (Roblox’s version of Lua) can only be accessed from the script it was declared in, there are no reasons to not use locals (other than preference).

2. Don’t use deprecated methods
You’re using methods such as :isA and :connect, these methods are deprecated and should not be used, ever. Their replacements are :IsA and :Connect, respectively (note the capitalisation). You can check if a method has been deprecated by checking the roblox dev wiki and looking for a deprecated notice, like in this image:


The notice should also provide a link to the method you should be using instead. Deprecated methods are also highlighted (I think) when you’re coding in Roblox studio

3. Only use :IsA when needed
When checking an Instance’s class, if you don’t need to be checking for an abstract/base class (e.g. BasePart, Constraint) you should be indexing the .ClassName property instead.
Example: if workspace.Model.ClassName == "Model" then ...

:IsA takes around twice as long as simply using the .ClassName property. (and :isA is even slower)


A quick solution for fixing these
Press Ctrl + Shift + F to open the Find in all Scripts menu, then change all instances of isA to IsA, and all unneeded IsAs to their .ClassName equivalent (do this manually, or you can use regex if it supports that)

1 Like

u mathematical genius.
image
Why am I dumb.