Button.Activated:Connect() seemingly doesn't fire despite being properly coded

Activation doesn’t fire at all. I’m confused what’s going on:

--Important button hovers
HoverInfo = TweenInfo.new(.25,Enum.EasingStyle.Circular,Enum.EasingDirection.Out,0,false,0)
function HoverAction(button,response)
	if response == true then
		TweenService:Create(button.Parent,HoverInfo,{Size = UDim2.new(1.1,0,1.1,0)}):Play()
	else
		TweenService:Create(button.Parent,HoverInfo,{Size = UDim2.new(1,0,1,0)}):Play()
	end
end

--Button activation (for frames and menu)
MenuInfo = TweenInfo.new(.125,Enum.EasingStyle.Circular,Enum.EasingDirection.Out,0,false,0)

function ButtonActivation(button,frame)
	print("test")
end

--Collect all important buttons for the menu
for index,object in pairs(Interface:GetDescendants()) do
	if object:IsA("ImageButton") and object.Name == "ButtonOpen" then
		object.MouseEnter:Connect(function()
			HoverAction(object,true)
		end)
		object.MouseLeave:Connect(function()
			HoverAction(object,false)
		end)
		object.Activated:Connect(ButtonActivation,object,object.Parent.Parent)
	end
end

I also tried to replace it with:

object.Activated:Connect(function()
	ButtonActivation(object,object.Parent.Parent)

This did nothing either. No error pops up. In the Activation function, nothing prints out.

I’m clueless.

1 Like

Note that the button hovers and their designated function work as intended (for scaling and reducing the buttons that are being hovered over).

However, it skips the activation line for some reason.

I don’t want to use MouseButton1 as .Activated is the engine’s standard. No UI is blocking the button as the hover feature works. So this should work as well.

It’s also a local script which is located in StarterPlayerScripts, but it should function regardless as the game has to wait for the UI to be present before executing anything else from the code shown above. Moving the code over to the UI itself does no help either - still the same result.

Just switched the line over to:
object.InputBegan:Connect(ButtonActivation,object,object.Parent.Parent)
Still nothing. Is Roblox Studio cursed?

AND I even just tried MouseButton1Down and still no success; my hands are literally tied.

i assume nothing in the function runs?

can you sprinkle prints everywhere to check where the code stops? if it even runs at all that is

Let me get some prints around the block and I’ll send where they’re not present.

The prints from yes2 and below aren’t firing at all. But then how is the script even firing the hover functions if it can’t send out a single easy print inside of their functions and between them?

Now it magically decided to start working again, but another issue arises:

Before it hits the Activation function, I did a quick test print to assure the objects are properly sent in. Objects themselves are sent to the function, but the print prints the name:

	print(object.Name,object.Parent.Parent.Name)

Resulting in:
image

But then when it hits the Activation function, it goes into a full disarray:

function Activation(buttonactivated,frame)
	print(buttonactivated.Name,frame.Name)
end

“attempt to index number with ‘Name’” (but this only applies for one of the 2 objects, but the objects that are being sent to the function are literally… a frame and an imagebutton.

Now my question is:
where the hell did the number come from like what

Now it all magically started working again with no fixes, so now my concern is - how will I put a game live if the game engine wants to be bipolar and not run things here and there although they are properly coded?

Like, is there anything someone can suggest me in terms of this?

what if you get rid of “pairs”?

and then just do if object:IsA("Something") then

yes but there are plenty of buttons in the UI, so this eases up the work

well, not plenty, but 5; if it does start happening again, that may need to be route to get it fixed

but still, it’s funny how studio is just blocking out from a readable code :joy:

it’s the only thing i can suggest, sorry

1 Like

no worries; I appreciate your time helping me with this :heart:

I’m just saying that it’s funny how Lua can’t properly read out the code that is simply written

The first two parameters are overwritten by the event, the Activated event passes two automatically

Same with the MouseButton1Down event, the first two default parameters are the X and Y positions of where the button was clicked.

Eh another thing is to make your TweenInfos (MenuInfo and HoverInfo) as well as your functions local or “named” (at this point just make everything local)

Oh I left out this somehow:
object.Activated:Connect(ButtonActivation,object,object.Parent.Parent)
You can not add parameters to the RBXScriptConnection like this, declare a small lambda function and call your script manually or just do it in the lambda one (in the script below it’s the correct way)

But here is a fully rewritten version:

-- Constants
local HoverInfo = TweenInfo.new(.25,Enum.EasingStyle.Circular,Enum.EasingDirection.Out,0,false,0)
local MenuInfo = TweenInfo.new(.125,Enum.EasingStyle.Circular,Enum.EasingDirection.Out,0,false,0)

--// Functions
local function HoverAction(button,response)
	if response == true then
		TweenService:Create(button.Parent,HoverInfo,{Size = UDim2.new(1.1,0,1.1,0)}):Play()
	else
		TweenService:Create(button.Parent,HoverInfo,{Size = UDim2.new(1,0,1,0)}):Play()
	end
end

local function Activation(buttonactivated, frame)
	print("test")
end

--Collect all important buttons for the menu
local function iterate()
    --// Wrap it into a function for better formatting
	for index,object in pairs(Interface:GetDescendants()) do
		if object:IsA("ImageButton") and object.Name == "ButtonOpen" then
			object.MouseEnter:Connect(function()
				HoverAction(object,true)
				--// personally I use -> task.spawn(HoverAction, object, true)
			end)
			object.MouseLeave:Connect(function()
				HoverAction(object,false)
			end)
			object.Activated:Connect(function()
			     Activation(object,object.Parent.Parent)
			end)
		end
	end
end

--// Calls
task.spawn(iterate)

I might have misspelt some words, idk
Added and fixed some stuff cuz the original message was pure retardness from me lmaoo
I think everything is in order, feel free to ask me if you have any other questions :heart:

1 Like

Oh wow, thank you for that! I appreciate the time you took to explain everything as well as give it a re-write.

Yeah, I’m definitely going to take these tips of yours in account as I continue coding this further. Will definitely ask you if something slips through tho! :heart:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.