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)