Weird MouseLeave Tween Bug

For better context on the video, this is an bug that happens when the player leaves the button quickly and would go down, I find this odd as MouseEnter isn’t affected by this.
I’ve looked at previous devforums about this issue but neither do any of them have the same issue as I, I could be wrong and can be a scripting error I made some where.
I’ve tried tweaking the adding and subtraction on MouseEnter and MouseLeave they might be the issue but not quite sure.

for i, button in pairs(script.Parent:GetDescendants()) do
	if button:IsA("ImageButton") then
		button.MouseButton1Up:Connect(function()
			if button:FindFirstChild("mapName") then
				local remote = game:GetService("ReplicatedStorage"):WaitForChild("OnMapSelection")
				remote:FireServer(button:FindFirstChild("mapName").Text)
			else
				warn("Map title not found.")
				return
			end
		end)
		-- mouse functions
		button.MouseEnter:Connect(function()
			tweenService:Create(button, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.In), {Position = UDim2.new(button.Position.X.Scale, button.Position.X.Offset, button.Position.Y.Scale - 0.05)}):Play()
		end)
		button.MouseLeave:Connect(function()
			tweenService:Create(button, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.In), {Position = UDim2.new(button.Position.X.Scale, button.Position.X.Offset, button.Position.Y.Scale + 0.05)}):Play()
		end)
	end
end

Make sure to always cache the old values of objects you plan to tween, or else you create room for bugs. By simply doing that, I’m 99% sure the above error won’t occur:

local oldY = button.Position.Y.Scale
button.MouseEnter:Connect(function()
	tweenService:Create(button, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.In), {Position = UDim2.new(button.Position.X.Scale, button.Position.X.Offset, oldY - 0.05)}):Play()
end)
button.MouseLeave:Connect(function()
	tweenService:Create(button, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.In), {Position = UDim2.new(button.Position.X.Scale, button.Position.X.Offset, oldY + 0.05)}):Play()
end)
1 Like

Had this in mind before just didn’t think It’d work, besides that thanks for solving it more simpler than I thought.

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