Button sometimes does not open the GUI, no errors or warnings thrown

So, I’m trying to make a pets button to open a GUI with them (just like in simulators), the problem is, that the UI does not open all the time the button is pressed. I have no clue why this is happening and it may be just a dumb error of mine. (Also I know that this is my second question in a matter of 2 days)

Script of the button:

local ts = game:GetService("TweenService")

local function TweenUI(object, info, goal)

	local tween = ts:Create(object, info, goal)
	tween:Play()
end

local tweenInfo = TweenInfo.new(
	.2,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.In,
	0,
	false,
	0
)

local goal = {
	["Position"] = UDim2.new(0.05, 0,0.049, 0)
}

local goalOutL = {
	["Position"] = UDim2.new(0.043, 0,0.038, 0)
}

script.Parent.MouseButton1Down:Connect(function()
	script.Parent.Parent.Parent.PetsUI.Enabled = true
	script.Parent.Parent.Enabled = false
	
	TweenUI(script.Parent.Parent.Parent.PetsUI.Gradient, tweenInfo, goal)
	TweenUI(script.Parent.Parent.Parent.PetsUI.Outline, tweenInfo, goalOutL)

	local blur = Instance.new("BlurEffect")
	blur.Parent = workspace.CurrentCamera
	blur.Size = 12
end)

The Issue:

1 Like

Have you tried printing the result inside MouseButton1Down is being fired?

Not yet, let me try to do that real quick.

It seems to print only when it opens the UI window, else it ignores it, maybe something with recognizing the click event?

Alright, Figured it out, there’s a problem wit the icon, it seems to block the button.

1 Like

Not quite sure how to fix it though, Z-index either hides it or makes it blocked since the icon will interfere.

You could just use the Icon instead, change the Icon to ImageButton.

1 Like

Had to change it to imagelabel, for some reason the plugin imported the icon as a button, and interference between the two was made, cause it registered a click on the imageButton, not the pets button. Thanks for you time though, I appreciate it a lot!

How about check if the mouse is hovering the Icon with MouseEnter and MouseLeave functions and use Mouse.Button1Down:

local IsHovering = false

Icon.MouseEnter:Connect(function() IsHovering = true end)
Icon.MouseLeave:Connect(function() IsHovering = false end)

Mouse.Button1Down:Connect(function()
    if IsHovering then
        ...
    end
end

nah, It’s fixed as I stated in the message above you! I just had to covert it to a label since it got imported as a button.

1 Like