Button function not working properly

Currently, I’m making a button on the player’s screen that fades in and out depending if their mouse is hovering over it or not, as well as completely fading upon clicking on it. While my hovering functions work as intended, when I click on the button, it only fades as if it were executing the hovering function, when I would like it to fade completely. How do I go about fixing this?

Here is a video of my issue:

3 Likes

Honestly, this is just a guess – But try setting isHovering to something other than a boolean value (or nil) when the updateGameplayTransition() function is called? I highly doubt this would work, and I know that false isn’t exactly nil, but I know they’re both considered false values per the documentation.
image

1 Like

Unfortunately, it did not work. Tried strings, numbers, no luck.

2 Likes

One method that could be used is storing the state of the button.

local b_state = 0

button.MouseEnter:connect(function()
	if b_state == 0 then
		b_state = 1
		
		for i=0,0.5,0.05 do
			if b_state ~= 1 then return end
			task.wait()
			button.TextTransparency = i
		end
	end
end)

button.MouseLeave:connect(function()
	if b_state == 1 then
		b_state = 0
		
		for i=0.5,0,-0.05 do
			if b_state ~= 0 then return end
			task.wait()
			button.TextTransparency = i
		end
	end
end)

button.Activated:connect(function()
	updatePlayerCount:fireServer()
	
	updateCharacterAppearance()
	
	if b_state ~= 2 then
		b_state = 2
		button.TextTransparency = 0
		
		for i=0,1,0.1 do
			task.wait()
			button.TextTransparency = i
		end
	end
end)

In the above example, I went with 0=Unhovered, 1=Hovered, and 2=Clicked.

1 Like

Store the MouseEnter (and MouseLeave) connections in a variable. Then when clicked check if its hovering and if it is disconnect the connection

local entercon,leavecon
entercon = button.MouseEnter:Connect(function() -- Bla bla bla
leavecon = button.MouseLeave:Connect(function() -- Bla bla bla
function updateGameplayTransition()
   if isHovering or not isHovering then
      entercon:Disconnect()
      leavecon:Disconnect()
      isHovering = nil
      -- Run the rest of the code
   end
end

In my script, I’m using the variable isHovering. And similarly to your method, it is used to check the state of the button. By using your method, wouldn’t the function yield the same problem? Because your variable uses three different values, similarly to isHovering in the same context to identify whether the mouse is hovering, not hovering, and clicking the button.

Strangely enough, this didn’t work either. Would it be possible any other way to disconnect or “destroy” a function in any other way? Unless somehow my updateCharacterAppearance() function somehow has an influence.

Strange, because it should work, maybe call the update gameplay function first

Okay, so the button disappears upon clicking initially now. But when the new character is applied, it reappears. How might this be?

Probably try disabling Reset on Spawn on the Screen Gui through properties

1 Like

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