Help with GUI buttons

Try doing that, then it should work.

Is the titlescreen gui a descendant of buttons?

I have a test script that does the thing i want
image
but I want to be able to add as many buttons as i want without copy pasting the script

what is the parent of the titlescreen gui?

nope
image

– Should work now

-- If my calculations are correct then this **Script** should work
local Rep = game:GetService("ReplicatedStorage")

local Buttons = script.Parent -- place this script inside buttons folder.
local ActualButtons = script.Parent.Parent:WaitForChild("TitleScreen").Backround.Button

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

wait what!?! What did you change? IT WORKS!!!

I added local ActualButtons —

Wait… is a frame named “Button” supposed to be added for every new button?

Yeah,
image

Ok then change script to this:

-- If my calculations are correct then this **Script** should work
local Rep = game:GetService("ReplicatedStorage")

local Buttons = script.Parent -- place this script inside buttons folder.
local ActualButtons = script.Parent.Parent:WaitForChild("TitleScreen").Backround

for i, item in pairs(Buttons:GetDescendants()) do
	if item:isA("ObjectValue") then
		for i, button in pairs(ActualButtons:GetDescendants()) do
		if string.lower(button.Name) == string.lower(tostring(item.Value)) then -- item.Value should be the button
			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 removed .Button from ActualButtons Variable

I also think you are able to change it to local script.

what I dont understand is, why going inside the TitleScreen and finding the “real button” works but not when finding the button through object value…

becuase the object value is supposed to hold the actual button ¯_(ツ)_/¯

I don’t know… I know how to script in some parts that I don’t understand.

1 Like

– I don’t know why I did this for no reason…