Frame is acting weird

Hey,

I want a system that makes an info frame visible whenever the cursor is over a button on the computer or when a finger is holding down a button on the phone. This frame should become visible and follow the cursor, disappearing when the cursor is no longer over the button or when the finger is no longer holding down the button on the phone. It works… almost.

Problem is that it doesn’t become visible when it should. What makes it even stranger is that its visibility becomes true when it should, but the frame is still not visible. Even stranger, when I press another button while the cursor is over it, it becomes visible, and when I move the cursor a bit, the frame disappears. What on earth is happening? It always becomes visible when I press, for example, the W or U button and disappears when I move the cursor.

I need help.

Here is the local script:

local frame = script.Parent
local UserInputService = game:GetService("UserInputService")
local button = script.Parent.Parent
frame.Visible = false
button.MouseEnter:Connect(function()
	frame.Visible = true
end)
button.MouseLeave:Connect(function()
	frame.Visible = false
end)

UserInputService.TouchLongPress:Connect(function()
	frame.Visible = true
end)

UserInputService.TouchTap:Connect(function()
	frame.Visible = false
end)
UserInputService.InputChanged:Connect(function(input)

	local mousePosition = input.Position
	frame.Position = UDim2.new(0.4, mousePosition.X, 0.4, mousePosition.Y)
end)

1 Like

The script seems to work fine for me based on your description. Try make sure there isn’t another script that could be interferring with this one, You could also check if you’ve correctly referenced the frame and that there’s no output errors and etc.

I tried to check if any other script would affect to this frame but I didn’t find any other.
Here is video which shows my problem:

I tried your code but it is really buggy…

The issue with your code was that the position of the info frame was being set based on the mouse position, rather than the position of the button. This caused the frame to appear in unexpected locations or not appear at all when the cursor was over the button

I tried to modify the code, and I did the correct code, and it works more than perfectly

local frame = script.Parent
local UserInputService = game:GetService("UserInputService")
local button = script.Parent.Parent
frame.Visible = false

button.MouseEnter:Connect(function()
	frame.Visible = true
end)

button.MouseLeave:Connect(function()
	frame.Visible = false
end)

UserInputService.TouchLongPress:Connect(function()
	frame.Visible = true
end)

UserInputService.TouchTap:Connect(function()
	frame.Visible = false
end)

UserInputService.InputChanged:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		local buttonPosition = button.AbsolutePosition
		local buttonSize = button.AbsoluteSize
		local mousePosition = input.Position
		
		if mousePosition.X >= buttonPosition.X and mousePosition.X <= buttonPosition.X + buttonSize.X and
			mousePosition.Y >= buttonPosition.Y and mousePosition.Y <= buttonPosition.Y + buttonSize.Y then
			frame.Visible = true
		else
			frame.Visible = false
		end
	end
end)
1 Like

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