SurfaceGui mouse events broken

I’m having a problem with using MouseEnter and MouseLeave on a SurfaceGui. It works fine if I move my mouse into it, but if I keep my mouse still and walk so that the mouse is over the button, it doesn’t detect that my mouse entered. The same thing happens with MouseLeave. The SurfaceGui is in StarterGui adoorned to a part.

local Frame = script.Parent

local TweenService = game:GetService("TweenService")
local ButtonTweenInfo = TweenInfo.new(0.3, Enum.EasingStyle.Back, Enum.EasingDirection.Out)
local ButtonColorInfo = TweenInfo.new(0.3, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)

local PurchaseButtonSize = UDim2.new(0.3, 0, 1, 0)
local MouseenterSize = UDim2.new(0.4, 0, 1.1, 0)
local SizeWhenClicked = UDim2.new(0.5, 0, 1.2,0)

Frame.ChildAdded:Connect(function(Child)
	if Child:IsA("TextButton") then
		Child.MouseEnter:Connect(function()
			print("Entered")
			local TweenSize = TweenService:Create(Child, ButtonTweenInfo, {Size = MouseenterSize})
			local TweenColor = TweenService:Create(Child, ButtonTweenInfo, {BackgroundColor3 = Color3.fromRGB(255, 255, 255)})
			TweenSize:Play()
			TweenColor:Play()
		end)

		Child.MouseLeave:Connect(function()
			print("Left")
			local TweenSize = TweenService:Create(Child, ButtonTweenInfo, {Size = PurchaseButtonSize})
			local TweenColor = TweenService:Create(Child, ButtonColorInfo, {BackgroundColor3 = Color3.fromRGB(0, 255, 17)})
			TweenSize:Play()
			TweenColor:Play()
		end)

		Child.MouseButton1Up:Connect(function()
			local TweenSizeHover = TweenService:Create(Child, ButtonTweenInfo, {Size = MouseenterSize})
			local TweenSizeLeftHover = TweenService:Create(Child, ButtonTweenInfo, {Size = PurchaseButtonSize})
		end)

		Child.MouseButton1Down:Connect(function()
			local TweenSize = TweenService:Create(Child, ButtonTweenInfo, {Size = SizeWhenClicked})
			TweenSize:Play()
		end)
	end
end)

Dang the video isn’t working its just showing the bug tho

MouseEnter and MouseLeave only gets triggered whenever the mouse actually moves, not the player. Your best bet is to check each frame for gui objects under the mouse.

Check PlayerGui:GetGuiObjectsAtPosition
Set the X and Y to the mouse X and Y.

2 Likes

It worked THANK YOUUUYUYU I’ve been trying to fix this for 2 days now…

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