Help with GUI buttons

As the title suggests, I need some help with GUI.

I am trying to make a script that when you hover over a button it does a cool animation. Where im stuck is that I’m trying to make it that no matter how many buttons I add to the GUI screen I won’t need to configure my script and manually wire them to work for each one I add.

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

I tried to do this with Gui buttons:
image


I go through a folder that has object values to buttons, and make a :Connect function for each (Entering/Leaving)
This for some reason doesn’t work. It doesn’t output an error either. Anybody have a solution? Please help me…

:frowning:

1 Like

Have you put prints in each if statement to see where the code is going?

1 Like

Yup:
image

Any help would be appreciated. Ask me if you have any questions!

You could do this:

local button = <button location>

button.MouseEnter:Connect(function()
        <show the animation>
end)

button.MouseLeave:Connect(function()
        <stop the animation>
end)

I’m dumb, that’s what you did.

1 Like

Is this a local script?

– If my calculations are correct then this Script should work

local Rep = game:GetService("ReplicatedStorage")

local Buttons = script.Parent -- place this script inside buttons. If my calculations are correct your buttons should be in the Buttons Folder

for i, item in pairs(Buttons:GetDescendants()) do
	if item:isA("ObjectValue") then
		local check = Buttons:WaitForChild(tostring(item.Value))
	    if check then
			if check:isA("GuiButton") then
				check.MouseEnter:Connect(function()
					print("Enter")
				end)
				check.MouseLeave:Connect(function()
					print("Leave")
				end)
			end	
			end
		end
	end

It looks like the issue is that you are looping through the Buttons folder and not getting the contents inside of the TitleScreen.

Essentially what your script is doing is checking if the folder “TitleScreen” is an objectValue, which of course, it isn’t. maybe try getting the contents with something like item:GetChildren()[1].

im dumb, you used getdescendants, I’ll think of something soon

1 Like

– If my calculations are correct then this Script should work
– Place the Script in the buttons folder.

local Rep = game:GetService("ReplicatedStorage")

local Buttons = script.Parent -- place this script inside buttons folder.

for i, item in pairs(Buttons:GetDescendants()) do
	if item:isA("ObjectValue") then
		for i, button in pairs(Buttons:GetDescendants()) do
		if string.lower(button.Name) == string.lower(tostring(item.Value)) then -- item.Value should be the button name
			if button:isA("GuiButton") then
				button.MouseEnter:Connect(function()
					print("Enter")
				end)
				button.MouseLeave:Connect(function()
					print("Leave")
				end)
			end	
		end
	  end
	end
end	

I tried it, but sadly it doesnt work :pensive:
Thanks for trying though!

Is the parent of the script Buttons?

yeah:
image

It currently works in script and not local script but do you want me to fix it to local script?

yes please!
let me try it on regular script

You could probably make it fire a remote event for client instead of print. and then you can add a local script that checks if it is fired and print(“whatever you want”) if true

I tried it with a regular server script, and same results. Oof

That wouldn’t make sense though, if it doesn’t print then it wont fire a remote event either. I think its the problem of how I played out the coding, for example this image:
image
Is using :Connect() from the beggining
while im using a for loop

Where is the actual button located?

And shouldn’t you put buttons and it’s descendants in a gui?

image